Solve the problem that the content in success is unresponsive when using ajax

Recently, when I used Ajax in a project, I found that the value returned by the controller did not respond in Ajax.

The module in success as shown in the figure has no response.
Insert picture description here

Consider whether the front end does not return data, use the postman tool to test, the data is indeed sent back to the front end.

Finally found the problem, make a record here.

Conclusion : Since this ajax request submits a form form, submit is used on the type attribute of the input to realize the submission of the form form. This will make the page refresh, but ajax does not cause the page to refresh. Ajax's async (asynchronous) attribute is true by default . What really causes the page to refresh is the input tag of type submit, which will force the page to refresh, and the page refreshes. , The information returned by ajax will be passed to another page, and the module in success will naturally not be executed again. Solution: 1. Set the async attribute of the ajax request to false. 2. Set the type attribute of input to button, and use other methods to implement data submission.

Insert picture description here


Insert picture description here

// submit 改为 button
<input type="submit" />

<input type="button" />

Guess you like

Origin blog.csdn.net/Hambur_/article/details/113243785