Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

javascript - Response status is '0' in jquery ajax

I'm using a jquery ajax for storing a data in the database. I call a service through a url and send data to it in the following way:

$.ajax({
                        type: "POST",
                        url: "http://192.168.250.118:8080/rest_service/rest/user",
                        data: JSON.stringify({ "loginName": "[email protected]", "mobile": "1234567890" }),
                        async: false,
                        contentType: "application/json",
                        crossDomain: true,
                        success: function(data){
                            alert("success");
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown){
                            console.log(XMLHttpRequest);
                            console.log(textStatus);
                            console.log(errorThrown);
                        }
                    });

When I execute this, I get this error:

{"readyState":0,"status":0,"statusText":"error"}

This is what I get when I look for errors in network:

enter image description here

But, if I try using postman, the data is getting stored and I get 200OK response. What's wrong with the above code? What should I change?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Stringify the data before sending - data: JSON.stringify({ "loginName": "[email protected]", "mobile": "1234567890" }) amd contentType:"application/json"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...