[英]jquery dynamic content on ie
我正在開發的網站有問題。 動態加載的div(ajax)在IE9中為空,在firefox上效果不佳(php無法編譯),我可以在div中讀取我的php文件的源代碼。 我嘗試了很多解決方案,例如從GET更改為POST或向URL添加唯一的ID或發出異步請求,但內容絕對為空。 有任何想法嗎? 謝謝
function pageload(hash) {
if(hash == '' || hash == null)
{
document.location.hash = "#php"; // home page
}
if(hash)
{
getPage();
}
}
function getUniqueTime() {
var time = new Date().getTime();
while (time == new Date().getTime());
return new Date().getTime();
}
function getPage() {
var str = getUniqueTime();
console.log(str);
var data = 'page=' + encodeURIComponent(document.location.hash);
$('#content').fadeOut(200);
$.ajax({
url: "loader.php?_=" + str,
type: "POST",
data: data,
cache: false,
success: function (html) {
$('#content').fadeIn(200);
$('#content').html(html);
}
});
}
編輯:
//loader.php
<?
require_once('session.class.php');
require_once('user.class.php');
$se = new session();
$lo = new user();
$se->regenerate();
if(isset($_POST))
{
$alpha = (string) $_POST['page'];
if($alpha == '#php')
{
include 'homeloader.php';
}
else if($alpha == '#cplus')
{
include 'cplusloader.php';
}
else if($alpha == '#web')
{
include 'underloader.php';
}
else if($alpha == '#about')
{
include 'underloader.php';
}
else if($alpha == '#social')
{
include 'socialloader.php';
}
}
else
$page = 'error';
echo $page;
?>
嘗試這個:
//on click of a button:
$("#button").live("click", function(){
//get you string data
var str = "test";
//do new version of ajax
$.post("loader.php", {str:str}, function(html){
$('#content').html(html);
});
});
而且您不再需要使用AJAX方法$ .post效果驚人
php doesn't compile
? async request
? 實際上沒有指定ascync: true
,請求是異步執行的,在jQuery 1.8版本中根本沒有同步的AJAX請求。 附加一個錯誤處理程序,您將看到您的請求可能導致錯誤:
...
cache: false,
success: function (html) {
$('#content').fadeIn(200);
$('#content').html(html);
},
error: function (a,b) {
alert('Error!');
}
...
通常,AJAX由兩部分組成-客戶端和服務器端。 我沒有在您的問題中看到服務器端發布。 您必須檢查兩個。 使一個簡單的loader.php
返回success
的字符串,並擺脫所有額外的獲取參數。 首先在瀏覽器中測試您的php文件,以確保其正常工作。 檢查FireBug中的javascript錯誤...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.