我使用jquery-1.7.1.min.js。
简单示例:
<script language="JavaScript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "/ajax/test.php",
data: "name=John&location=Boston"
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
</script>
在Opera,Chrome,FireFox,Safari中显示提醒消息,但在IE7-IE9中不显示提示消息。哪里有问题?怎么解决?
答案 0 :(得分:2)
有同样的问题。通过向php部分添加标题解决(test.php)
header("Content-type: text/html; charset=windows-1251");
答案 1 :(得分:0)
尝试将其更改为使用&#39;成功&#39;参数而不是“完成”&#39;方法。我也改变了#34;语言&#34;属性为&#34;键入&#34;
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "/ajax/test.php",
data: "name=John&location=Boston",
success: function( msg ) {
alert( "Data Saved: " + msg );
}
});
});
</script>
答案 2 :(得分:0)
尝试将数据类型以及您提供的其他选项包括在内。
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "/ajax/test.php",
data: "name=John&location=Boston",
dataType: 'json', // <-- OR HTML,XML etc
success: function( msg ) {
alert( "Data Saved: " + msg );
}
});
});
</script>
答案 3 :(得分:0)
另一种方法
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
type: "POST",
url: "/ajax/test.php",
data: "name=John&location=Boston",
dataType: "text",
complete: function(msg,status) {alert( "Data Saved: " + msg.responseText );}
});
});
</script>
另一种解决方案,请尝试以下
<script type="text/javascript">
$(document).ready(function()
{
$.post('/ajax/test.php',{name:'John',location:'Boston'},
function(data) {alert( "Data Saved: " + data );}
);
});
</script>
并在test.php标题中添加:
<?php
header("Cache-Control: no-cache");
header("Pragma: no-cache");
echo "It works !" // Be positive :-)
?>