weixin_33712987 2010-08-27 17:38 采纳率: 0%
浏览 70

jQuery Ajax POST不成功

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!'); }
});
  • 写回答

3条回答 默认 最新

  • weixin_33739523 2010-08-27 17:44
    关注

    What handler gets called? The success or error handler? Can you elaborate what "doesn't work" means?

    You probably want alert more information in your error handler, like so:

    error: function(XMLHttpRequest, textStatus, errorThrown) {
       //console.log is better at least for debugging. You can change this back to alert 
       //when your code goes into production
       console.log("Update unsuccessful. Status: ", textStatus, " error thrown: ", errorThrown);
    }
    

    textStatus should give you an idea as to what the problem could be. Possible values are "timeout", "error", "notmodified" and "parsererror". Once you figure out the actual error, please update the question.

    Also if you have Firebug check the Net tab to see the request and the response. A few common sources of errors:

    • Violating same-origin policy. You cannot make an AJAX to a different URL from the parent page.
    • Server-side errors. If your server returns something like a 500 response code, the request will fail.
    • Parsing errors. If you're expecting a specific response format like json or xml, and if the response is not in that format, the AJAX request will be unsuccessful.
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!