The error code of ajax requests is 0.
When ajax is used to request data from the background today, an error occurs, prompting that the status code is 0. The background adopts the spring mvc Architecture.
What does the status code 0 mean? After searching, it means (not initialized) that the send () method is not called. My original code is as follows:
$. Ajax ({url: "test", type: "post", data: {blogTitle: $ ("# form1 input "). val (), blogType: $ ("# form1 option: selected "). val (), article: htmlcontent}, dataType: "json", success: function (data, textStatus) {if (data. flag = "success") {alert ("published successfully! "); Window. location. href = 'HTTP: // www.baidu.com '; }}, error: function (XMLHttpRequest, textStatus, errorThrown) {alert (XMLHttpRequest. status); alert (XMLHttpRequest. readyState); alert (textStatus );}});
Check it carefully. It seems that nothing is wrong. Besides, the data can be normally received in the background, indicating that ajax still sends data. This is the parameter information printed in the background.
Another thought turned out to be a problem with the form:
<Form onsubmit = "addBlog ();"> // skipped <button type = "submit"> post a blog </button> </form>
As you can see, I added the type = "submit" attribute to the button tag, but this will generate a new form click submission. Originally, a form will be submitted when the form click button by default, when button type = "submit", a new first submission is generated, resulting in a change in the form event before ajax is executed.
Solution:Change the code above:
<Form onsubmit = "return false"> // <button type = "addBlog ()"> post a blog </button>
The above Article quickly solves the problem that the error code of ajax requests is 0, which is all the content that I shared with you. I hope you can give us a reference and support the help house.