XMLHTTPRequest不适用于IE以外的浏览器

时间:2011-11-08 12:50:54

标签: xmlhttprequest

我正在尝试使用基于WCF Rest的服务获取一些数据。

这是我的代码。

jQuery.support.cors = true;

        $.ajax({
            url: http://localhost:2545/Service/GetData,
            data: JSON.stringify(temp),
            beforeSend: function (xhr) { xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); },
            type: "POST",
            contentType: "application/json charset=utf-8",
            dataType: "Json",
            crossdomain: true,
            success: function (result) { ProximitySucceeded(result) },
            error: function (result) { debugger; ServiceFailed(result) }
        });

我的网站正在http://localhost:1600上运行,服务在http://localhost:2545

它的IE工作正常。但是在chrome / firefox / safari上返回此错误 “Access-Control-Allow-Origin”不允许“原始http://localhost:1600。”

请帮助,因为不能从IE以外的任何浏览器访问该服务。

感谢。 莫希特。

1 个答案:

答案 0 :(得分:0)

我认为这可能算作跨站点脚本并被拒绝,因为不同的端口使其成为不同的域。

要解决此问题,您可能需要设置代理。

希望有所帮助

相关问题