加www的网址jQuery的阿贾克斯不工作 [英] jQuery ajax doesn't work on url without www

查看:87
本文介绍了加www的网址jQuery的阿贾克斯不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery的AJAX脚本下面没有在我的网站工作,如果网​​址是加www。我检查了Firebug的,它不会发送Ajax调用。

  $。阿贾克斯(
    {
        键入:POST,
        网址:http://www.mysite.com/beta/products.php
        数据:page_type =指数和放大器;排序= relevancerank和放大器; CartId =< PHP的echo $ CartId;>&安培; HMAC =< PHP的echo $ HMAC;>????,
        成功:函数(MSG)
        {
            $('#内容持有人)HTML(MSG);

        },
        错误:函数()
        {
            (在更新时出现错误尝试重新在一段时间。)警报;
        }
    });
 

解决方案

我假设调用文档的URL被引用为mysite.com,或subdomain.mysite.com?该XMLHtt prequest对象(即权力jQuery的Ajax调用发动机)不能完成跨域的请求。一个子域(如WWW)资格。请确保您的要求是相同的子域。

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.com/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");
        }
    });

解决方案

I'm assuming the calling document URL is referenced as "mysite.com", or "subdomain.mysite.com"? 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.

这篇关于加www的网址jQuery的阿贾克斯不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆