ajax请求返回到达不了success,statusText: "error" status: 0 readyState: 0

    xiaoxiao2021-04-01  38

    问题背景:

    误使用<from metod="post" action="/test"></form>表单

    在js代码中使用Ajax数据再次向后台提交请求 eg:url:"/test2"

    问题报错:

    后台正确返回"/test2"请求的内容,但是直接跳至ajax的error函数,查看报错为:statusText: "error" status: 0 readyState: 0 

    报错原因:同时使用表单提交和ajax数据请求,导致返回出错,

    解决方法:

    1、使用form表单或使用ajax的一种。

    2、网上貌似有使用preventDefault() 方法去解决问题的,当问题比较复杂的时候可以选择这一种,具体解决方法有待后续学习。

    参考链接:

    http://www.justinball.com/2013/02/25/jqxhr-returning-readystate-0-and-status-0/ 

    http://www.w3school.com.cn/jsref/event_preventdefault.asp

    转载请注明原文地址: https://ju.6miu.com/read-665659.html

    最新回复(0)