1

I've got a problem and I have no idea why it appears. The circumstances of its appearance are very strange for me...

I've got a POST REST service /login. It expects json {"email":email,"password":password}. I am using ajax and everything works correctly... except for the case when email (is in real format) contains '@' sign and some letters before and after( I know it is strange but only in this case such error appears). When I pass email i.e "mum@mum.com" then few things are happening:

  1. I see that browser sends GET request instead of POST and obtains 304 http status
  2. In the browser console I see infomation "The development server has disconnected. Refresh the page if necessary" and page refreshes automatically

The above things happen only when email is in format I described above.When I pass "aaa" or "aaa@" as email everything works correctly(browser sends POST request and I don't get error in console).

I honestly have no idea why this happens... would be extremely grateful for your help and I will answer all your questions concerning this.

PS. When I use REST web service tool in IntellJ everything always works fine.

    handleLogin() {
    const input = {
        email: this.state.email,
        password: this.state.password
    };

    $.ajax({
        url: CONST.USER_SERVICE + "/login",
        type: "POST",
        data: JSON.stringify(input),
        contentType: "jsonp"
    })
        .fail(function () {
            alert("Wrong data");
        })
        .always(function (arg1, arg2, arg3) {
            if (arg3.status === 200) {
                alert("ok!");
            }

        }.bind(this));
}
user2455862
  • 585
  • 10
  • 26
  • You can find answer here https://stackoverflow.com/questions/4508198/how-to-use-type-post-in-jsonp-ajax-call – Andrew Paramoshkin Jan 19 '18 at 13:22
  • `contentType: "jsonp"` makes no sense, maybe it should be `contentType: "json"`. – Musa Jan 19 '18 at 13:26
  • When I remove contentType: "jsonp" it works the same, when I changed to json (or application/json) also there is the same error. – user2455862 Jan 19 '18 at 13:27
  • have you tried adding `cache: false` in your Ajax call ? It is possible that the browser is catching a previous request for the same resource, resulting in Http 304 error. – derloopkat Jan 19 '18 at 14:08
  • Yes, I tried but it doesn't help. I think that it shouldn't call GET when I wrote POST and this is the problem. – user2455862 Jan 19 '18 at 14:27

1 Answers1

0

Try making the ajax request like data: input without stringify. Ajax expects an object.

  • jQuery Ajax can handle json as string and the object needs to serialized before sending. Why do you think this is related to the problem? – derloopkat Jan 19 '18 at 17:28
  • I have no idea why the problem depends on the text I send to web-service. I think that the clue might me this error in console, but I don't know what to change to make it disappear. – user2455862 Jan 19 '18 at 17:51