我无法使用jquery的ajax功能成功发布.
运行页面的URL为http:// localhost:9999,目标(Web服务)的URL为http:// localhost:8080.没有端口不相同,它们分别是9999和8080.@H_502_3@
请求:@H_502_3@
OPTIONS /profile/set_member HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Origin: http://localhost:9999 Access-Control-Request-Method: POST
$.ajax({ type: "POST",url: "http://localhost:8080/profile/set_member",contentType: "application/json",data: member,error: function(){ alert('Update Failed!'); },processData: false,success: function(){ alert('Update successful!'); } });
解决方法
这是跨域ajax调用的问题.基本上(至少在Firefox中),出于安全原因,POST请求被转换为OPTIONS请求.我昨晚在这里发布了同样的事情.
WCF Ajax Call not working with Jquery $.ajax@H_502_3@
我在localhost:23485上进行了$.ajax调用,在IIS上托管了http://localhost的Web服务.因为它们是不同的域,所以跨域开始并使事情变得困难.@H_502_3@