【问题标题】:Jquery Same Origin Ajax Call MistakeJquery同源Ajax调用错误
【发布时间】:2015-04-05 04:07:28
【问题描述】:

有问题的网站是 test1.guru99.com 我正在像这样制作 SAME ORIGIN

var myemail = "test@gmail.com";

       jQuery.ajax({
            type: 'GET', //Define the method type
            url:'http://test1.guru99.com/Customization/popup/subscription-list.php',
            data: {email: myemail},
            success: function(d) {
                console.log('success');
            },
        });

但我得到类似的错误

【问题讨论】:

    标签: javascript jquery ajax .htaccess joomla


    【解决方案1】:

    发生 CORS 错误是因为您的网站不是“test1.guru99.com”。它是“www.test1.guru99.com”。 (它会自动重定向

    因此,既然您希望脚本从同一个域运行,只需将域排除在外

    jQuery.ajax({
            type: 'GET', //Define the method type
            url:'/Customization/popup/subscription-list.php',
            data: {email: myemail},
            success: function(d) {
                console.log('success');
            }
        });
    

    (但不会解决500错误)

    【讨论】:

    【解决方案2】:

    您看到此错误是因为请求/接收站点的域不同。

    请求的站点是www.test1.guru99.com,接收者是test1.guru99.com。请注意,域的每个部分必须匹配,直至子域和协议。

    假设www. 子域指向同一个地方,我建议您修改$.ajax 调用以使用相对路径。

    【讨论】:

    • 感谢我能够解决 COR 问题。但我仍然收到 500 错误。是因为我使用的 Jquery 版本还是 htaccess?screencast.com/t/3xGGiJIw
    • 500 错误意味着您的服务器端代码存在问题。你需要调试你的 PHP。
    猜你喜欢
    • 2014-11-22
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多