Javascript Can';t将我的Json帖子发送到我的Web服务
我想将我的Json帖子发送到我的web服务,但我无法理解这个问题,因为我已经将jquery.support.cros=true设置为允许跨域支持,有人能告诉我我做错了什么吗。。。因为我的脚本在WEBAPPLICATION_1上,我的webservice在WEBAPPLICATION_2上,我使用的是jquery 1.7 min版本Javascript Can';t将我的Json帖子发送到我的Web服务,javascript,json,web-services,Javascript,Json,Web Services,我想将我的Json帖子发送到我的web服务,但我无法理解这个问题,因为我已经将jquery.support.cros=true设置为允许跨域支持,有人能告诉我我做错了什么吗。。。因为我的脚本在WEBAPPLICATION_1上,我的webservice在WEBAPPLICATION_2上,我使用的是jquery 1.7 min版本 <script type="text/javascript"> jQuery.support.cors = true; $.ajax({ type: "P
<script type="text/javascript">
jQuery.support.cors = true;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:13096/GetUpdatedData.asmx/UpdatedData",
data: 'Ip=' + '<%= Request.UserHostAddress%>' + '&location=' + window.location.href + '&Browser=' + BrowserDetect.browser + '&Version=' + BrowserDetect.version + '&Os=' + BrowserDetect.OS,
dataType: 'json',
success: function (msg) { alert(msg.d); },
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown); }
});
</script>
//我收到的错误是内部服务错误,我正在使用另一个javascript代码检测浏览器信息,所以这不是问题所在什么是
'Ip='+'
?您是否在服务器上动态生成Javascript,然后信任它?如果im发送数据:“{}”为空,它仍然不会命中服务,因此我认为Request.UserHostAddress不是problem@faester它的cors不是CRO:)您确定您的Web服务返回带有'application/json'
MIME的响应吗?只需尝试从ajax请求中删除数据类型:“json”
即可访问web服务。jQuery在检查响应的性质方面非常严格。
[System.Web.Services.WebMethod(EnableSession = true)]
public void UpdatedData(string Ip, string location, string Browser, string Version, string Os)
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create ("http://localhost:13096/Admin.aspx?Ip=" + Ip + "&location=" + location + "&Browser=" + Browser + "&Version=" + Version + "&Os=" + Os);
myReq.Method = "Get";
myReq.BeginGetResponse(ar =>
{
HttpWebRequest req2 = (HttpWebRequest)ar.AsyncState;
var response = (HttpWebResponse)req2.EndGetResponse(ar);
int numVisibleCookies = response.Cookies.Count;
}, myReq);
}