admin管理员组文章数量:1279017
The jQuery ajax script below doesn't work on my site if url
is without www. I checked Firebug and it doesn't send the ajax call.
$.ajax(
{
type: "POST",
url: ".php",
data: "page_type=index&sort=relevancerank&CartId=<?php echo $CartId;?>&HMAC=<?php echo $HMAC;?>",
success: function(msg)
{
$('#content-holder').html(msg);
},
error: function()
{
alert("An error occurred while updating. Try again in a while");
}
});
The jQuery ajax script below doesn't work on my site if url
is without www. I checked Firebug and it doesn't send the ajax call.
$.ajax(
{
type: "POST",
url: "http://www.mysite./beta/products.php",
data: "page_type=index&sort=relevancerank&CartId=<?php echo $CartId;?>&HMAC=<?php echo $HMAC;?>",
success: function(msg)
{
$('#content-holder').html(msg);
},
error: function()
{
alert("An error occurred while updating. Try again in a while");
}
});
Share
Improve this question
edited Mar 31, 2010 at 18:50
Veger
37.9k11 gold badges108 silver badges117 bronze badges
asked Mar 31, 2010 at 18:43
steamboysteamboy
1,1625 gold badges20 silver badges37 bronze badges
0
4 Answers
Reset to default 6I'm assuming the calling document URL is referenced as "mysite.", or "subdomain.mysite."? The XMLHttpRequest object (the engine that powers jQuery Ajax calls) can not perform "cross-domain" requests. A subdomain (e.g. 'www') qualifies. Make sure your requests are to the same subdomain.
You don't need to provide an absolute URL, you can simply provide a relative one, and it will work regardless if the your page is loaded with the www. subdomain or not:
//...
type: "POST",
url: "/beta/products.php",
//...
Is your server redirecting to the "www" domain possibly? This is probably just the same-origin policy preventing your outer page from accessing a different domain.
www. is just a naming convention - ajax will load on any address that can be looked up via dns, or it will work on an ip address as long as there is a server to respond to the request.
BUT - your page location and the ajax request need to be in the same domain for security reasons. To get round this restriction, you need to use something called JSONP
本文标签: javascriptjQuery ajax doesn39t work on url without wwwStack Overflow
版权声明:本文标题:javascript - jQuery ajax doesn't work on url without www - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241712a2364108.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论