The load method provided by Jquery

Jquery provides a method load to partially update the content of an element in the page. The load method receives three parameters load(请求路径,可携带数据,回调函数).

Among these three parameters, the request path is required, and it must be a backend path, not a path of a front-end page. It does not have routing support like vue. Therefore, whether the page or data is actually returned depends on what the backend returns to the frontend, because the return value of the backend only recognizes a string, and Json is essentially a string. If you have tried to test it, you will find that the backend will ResponseBody或者RestControlleralways return a frontend view path unless you use it. If these two annotations are not used and the returned type is not String, an exception will be reported for parameter transmission .

Portable data is optional. If the transfer needs to be a set of Json, 但请注意whether you pass parameters means which request method to use. When there is no parameter, load will send a get request, and when carrying parameters, load will send a post request.

The callback function is also optional, but it will not take effect before the request result takes effect on the page, that is to say, the callback function you write is only used to cooperate with load to do some display linkage, and it cannot achieve the return value after you The effect on the page is displayed after the callback function.

As mentioned earlier, whether you want to load the page or data depends on the cooperation of the backend. If the backend returns a json, it is the display data. If it returns an ordinary string, in a single project, such as jsp, it returns is a page. When the front and back ends are separated, the load method is best to just load data. Of course, if your situation allows, you can also receive the page path. For example, as mentioned above, your front end is a jsp technology that still needs to carry the web environment. There is a point that is easy to confuse, that is, when there are parameters 使用post缺能在效果上达到路径跳转的效果, it is necessary to explain it here, but from the perspective of Post requests, it can be used to jump pages. The difference between people and get is only the way of carrying parameters. , the cognitive barrier that causes the post to be unable to jump to the page is due to the interactive technologies commonly used in front-end development, such as ajax and axios, the post request encapsulated by these technologies does not support the page jump, and the post and load of the form are You can use post to jump to the page. Of course, it's not that ajax can't jump the page. You can use them to process the original request transaction, and finally use the window to jump the return path. If you are interested, you can search for the post request page jump code, and you will find that it will take a lot of effort to generate forms on the Internet to carry parameters and other mysterious codes. Originally, it is only for the direct exposure of the first parameter, and the second is to avoid the length limit of get. Thirdly, if the window path processing is too long, various problems may occur, but actually it makes the problem more complicated.

Guess you like

Origin blog.csdn.net/dudadudadd/article/details/130063340