jQuery的Ajax的POST不成功 [英] jQuery Ajax POST unsuccessful

查看:178
本文介绍了jQuery的Ajax的POST不成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法成功地发布使用jQuery的Ajax功能。

运行页面的URL是的http://本地主机:9999 ,目标(网络服务)的URL是的http://本地主机:8080 。没有端口是不一样的,他们分别是9999和8080。

下面是请求和jQuery阿贾克斯code。

请求:

 选项/型材/ set_member HTTP / 1.1
主持人:本地主机:8080
用户代理:Mozilla的/ 5.0(Windows系统; U; Windows NT的6.1; EN-US; rv中:1.9.2.8)的Gecko / 20100722 Firefox的/ 3.6.8
接受:text / html的,是application / xhtml + xml的,应用程序/ XML; Q = 0.9,* / *; Q = 0.8
接受语言:EN-US,EN; Q = 0.5
接受编码:gzip,紧缩
接收字符集:ISO-8859-1,UTF-8,Q = 0.7,*; Q = 0.7
保持活动:115
连接:保持活动
原产地:HTTP://本地主机:9999
访问控制请求-方法:POST
 

jQuery的阿贾克斯code:

  $。阿贾克斯({
        类型:POST,网址:HTTP://本地主机:8080 /型材/ set_member
        的contentType:应用/ JSON数据:成员,
        错误:函数(){警报(更新失败!); },
        过程数据:假的,
        成功:函数(){警报(更新成功!); }
});
 

解决方案

这是一个问题,跨域Ajax调用。基本上(至少在Firefox),POST请求转换为出于安全原因的OPTIONS请求。我遇到同样的确切的事情,昨晚,贴在这里。

<一个href="http://stackoverflow.com/questions/3578614/wcf-ajax-call-not-working-with-jquery-ajax">http://stackoverflow.com/questions/3578614/wcf-ajax-call-not-working-with-jquery-ajax

我有一个$就呼叫我正在在localhost:23485,对 HTTP Web服务://本地主机在IIS中承载。因为它们是不同的域,跨域踢,并提出刁难。

I'm unable to successfully post using jquery's ajax functionality.

URL of the running page is http://localhost:9999, URL of the target (web service) is http://localhost:8080. No the ports aren't the same, they are 9999 and 8080 respectively.

Below is the request and jquery ajax code.

Request:

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

jQuery ajax code:

$.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!'); }
});

解决方案

This is an issue with cross-domain ajax calls. Basically (at least in Firefox), a POST request is converted to an OPTIONS request for security reasons. I ran into the same exact thing last night, posted here.

http://stackoverflow.com/questions/3578614/wcf-ajax-call-not-working-with-jquery-ajax

I had an $.ajax call I was making on localhost:23485, to a web service on http://localhost hosted in IIS. Because they are different domains, cross-domain kicked in and made things difficult.

这篇关于jQuery的Ajax的POST不成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆