【发布时间】:2013-01-09 16:05:30
【问题描述】:
我正在尝试调用外部 Web 服务,它在 chrome 中可以正常工作,但在 Firefox 和 IE 中却不行。在chrome中,它返回'true',但在firefox中,它返回'0 error',这是我的完整代码...
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnCall").click(function (event) {
var campaignid = 1000007;
var r_source_id = 1000008;
var parameters = "{'CompanyName': '" + document.getElementById('txtCompanyName').value + "', 'name': '" + document.getElementById('txtName').value + "', 'title': '', 'email':'" + document.getElementById('txtEmail').value + "', 'phone':'" + document.getElementById('txtPhoneNo').value + "', 'web_url':'', 'no_of_emp':'0', 'c_Currency_id':'100', 'r_source_id':'" + r_source_id.toString() + "', 'industry_ID':'1', 'city':'', 'country_ID':'" + document.getElementById('ddlCountry').value + "', 'cur_solution':'','pur_timeline':'','comments':'', 'year_sell_erp':'2013', 'support':'', 'bpgroup_ID':'1', 'C_Campaign_ID':'" + campaignid.toString() + "', 'R_STATUS_ID':'1000033', 'C_Region_ID':'100', 'CreatedBy':'1000012', 'salesrep_id':'1000012', 'ad_org_id':'1000001', 'ad_client_id':'1000001', 'UpdatedBy':'100', 'AccessKey':'caff4eb4fbd6273e37e8a325e19f0991'}";
$.ajax({
type: "POST",
url: "http://cloudservice.softwareonthecloud.com/service.asmx/SetLead",
data: parameters,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
这里是我上传了这个函数URL for testing
【问题讨论】:
-
你是在加载 jQuery 两次吗?
-
您似乎正在尝试发出 CORS 请求。 jQuery 不支持 IE
-
有什么解决方案/技巧可以在 Firefox 中运行吗?
-
有一个解决方案可以在 Firefox 和 IE 中修复它。在您的服务器(为发出请求的页面提供服务的服务器)上创建一个代理脚本,为您从 Web 服务请求数据。让你的客户端脚本从你的服务器请求,你的服务器从网络服务请求,从而避免了跨域问题。
-
你知道它在 200 成功之前即使在 chrome 中也会返回一个 500 错误
标签: javascript jquery asp.net html web-services