当我将客户站点从开发站点移动到他们自己的站点(基本上使用 VPS 具有相同的设置)时,我的 jQuery 脚本停止工作。
jQuery(document).ready(function() {
jQuery('input[name=button]:button').click(function(){
jQuery("#show").html('<center><img src="http://xxxx/images/ajax-loader.gif"></center>');
jQuery.get("http://xxx/inc/usrreg_ajax.php",{
namn: jQuery("input[name='namn']").val(),
nyhetsbrev: jQuery("input[name='news']").val()},
function(data){
jQuery("#show").fadeIn("slow").html(data);
});
});
});
我正在使用 html
<div id="registering" style="margin-top: 15px;">
<div style="float:left;">
<label for="namn">Namn:</label><br/>
<input type="text" name="namn"><br/>
<input type="checkbox" name="news" value="ja">Ja, jag vill ha nyhetsbrev! <br/>
<div style="clear:both;"></div>
<input type="button" name="button" value="Anmäl dig!">
<div id="show"></div>
</div>
移动后我没有进行任何更改,并且 jQuery 脚本在开发站点上运行完美。
非常感谢您的任何意见!
祝一切顺利, 貂
最佳答案
xxx/inc/usrreg_ajax.php
与您的新网站位于同一域吗?
您必须记住,出于安全原因,有一个同源策略会阻止您从其他域 URL 执行 ajax 调用。
http://en.wikipedia.org/wiki/Same_origin_policy
Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
您可以使用 jsonp
进行不同的域调用,但您必须使用 jQuery.ajax
来实现,并且无法像这样简单地获取 html正如你现在所做的那样
关于javascript - jQuery ajax 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6496245/