ie浏览器的jQuery getJSON不能工作
Internet Explorer jQuery getJSON not working
我正在制作一个小脚本,通过php使用jquery的getJSON方法从数据库中获取一些数据。
的代码如下:
$(document).ready(function(){
var id = userid;
$('#a-div').after('<div id="data"></div><input type="button" id="getdata" value="Get Data">');
$('#getdata').click(function(){
$.getJSON('http://mysite.com/data.php?id=' + id, function(data) {
var notfound = data['notfound'];
var user = data['user'];
if(notfound == '1'){
$('#data').html("Not found");
}
else{
$('#data').html("Found , user is "+ user);
}
});//end of getJSON
});//end of click
}); //end of document ready
我的php脚本返回JSON数据如下所示:如果在数据库中找到数据-
{"notfound":"0","user":"john"}
如果数据库中没有数据-
{"notfound":"1","user":"none"}
这在Firefox, Google Chrome和Safari上工作完美,只是在Internet explorer(7,8,9)中不起作用。有谁能帮我一下吗?
p/S我在其他类似的帖子中尝试了一些技术,但不起作用。比如改变META内容类型
谢谢。
尝试将按钮放到 body>像这样:
$("body").append( /* markup for div and btn here */ );
…代替after().
也许ie浏览器需要很长时间来添加html,尝试使用live
$('#getdata').live('click', function(){
你正在使用非常丑陋的代码,在正文不正确之后编写任何HTML内容,为此你必须在正文中添加任何div并将你的cod附加到它,然后这段代码将在ie中工作
$(document).ready(function () {
$('#anydiv').html('<div id="data"></div><input type="button" id="getdata" value="Get Data">');
$('#getdata').click(function () {
alert("asd");
$.getJSON('/HowItWork/Index?id=' + 23, function (data) {
var notfound = data['notfound'];
var user = data['user'];
if (notfound == '1') {
$('#data').html("Not found");
}
else {
$('#data').html("Found , user is " + user);
}
}); //end of getJSON
}); //end of click
}); //end of document ready
这个适合我- jQuery.support.cors = true;
查找更多讨论http://jquery.10927.n7.nabble.com/jQuery-getJSON-response-not-working-with-IE-works-perfectly-in-firefox-safari-td81254.html
相关文章:
- 用javascript将script元素附加到头部;铬不能工作
- 为什么jQuery代码段在没有IFrame的情况下可以工作,而在有IFrame时却不能工作
- 为什么当async标志设置为false时,xmlhttprequest中的代码可以工作,而当它设置为true时却不能工作
- 引导程序's的javascript在本地工作,但在部署到服务器时不能工作
- JQuery脚本没有'Don’我不能工作两次
- "npm运行构建:css"不能工作,而当我自己运行脚本时是可以的
- ng样式在与的预标记中!重要的是不能工作
- angularjs 控制器在指令中使用控制器作为不能工作
- jQuery LightSlider不能工作,但在JSFiddle中工作得很好
- Javascript - 我如何让一个语句工作一次,如果它已经工作了 1 次,则不能工作,然后再次工作
- 我的查询获胜'因为一个剧本,它不能工作(它以错误的方式工作)!?但为什么呢?SESSIONS和PHP
- 我的Javascript代码没有'铬不能工作
- 使用JQuery调整图像大小和重新排列图像;第一次装载时不能工作
- 为什么不是'这个Javascript计算器不能工作
- Javascript在窗口中返回.onbeforeunload不会'铬不能工作
- Javascript代码包含在html中时可以工作,但单独加载/注入时则不能工作
- 简单的jquery选择器不会;铬不能工作
- 为什么不'这个Javascript函数不能工作
- 为什么不'这个js数组函数不能工作
- 视口比例;方向改变后不能工作