Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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": "tsample@gmail.com", "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

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

1 Answer

Stringify the data before sending - data: JSON.stringify({ "loginName": "tsample@gmail.com", "mobile": "1234567890" }) amd contentType:"application/json"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...