Some understanding-filters, interceptors, Ajax commits do not jump after, document.location.href invalid, callback function.

Source: Internet
Author: User

Workflow for filters and interceptors in 1.STRUTS2:

Request--> executes the custom filter DoFilter method before the Chain.dofilter () method and the Chain.dofilter () method in the Execute default filter DoFilter method before the code--Execute the default interceptor--Execute a custom interceptor--Access server resources (action,css,html,jsp ...) --Execute a custom interceptor--Execute the default interceptor--and execute the default filter in the DoFilter method after the Chain.dofilter () method code-- Executes the custom filter DoFilter method of the Chain.dofilter () method after the code--the client starts to execute the response response

Note: ① above the custom filter before the default filter execution is just a hypothetical order, which is the light and light default filter This implementation process has a lot of details, this online data or source analysis a lot.

② A custom filter has multiple words, the order of execution is related to the order in which you arrange it in Web. XML, the former executes first.

③ Note the request and response in this round-trip, the pre-and post-execution of multiple filters and the order in which the interceptors are executed are symmetric.

2.ajax synchronization is the Ajax thing is not done before, other things can not be done, to wait for it. Asynchronously, contrary to each other, is carried out in a non-impact manner.

3. Note One situation: ajax+submit+ synchronization ----is that you use AJAX to request the server, and the use of synchronous mode, and you are by clicking on the type of a button to trigger this Ajax.

This time, first you click on Submit, it will submit the form, but because you use the Ajax synchronous operation, submit the submission is blocked, Ajax first execute, this time, If you wrote document.location.href= ' xxx.html ' in the Ajax callback function (for example: success), it was executed, and indeed went to perform the jump, so Ajax was done, The next step is to complete the request submitted by the submit. Then again from xxx.html jump back to just that page (whether you submit the specific data submitted, in short, if the background does not perform jump/redirect, it will go back to the original page. )

That is, Ajax is as you want to do, but also from a page to the B page, but because of this type of the special, and let the B page jumped back to the a page, because this Ajax execution after the execution of the submit request process of processing quickly, you will feel like no effect, but you look closely , you will find that the Process page will refresh, in fact, the B page jumps back to the a page.

So when using Ajax to request, we need to use the button, rather than submit, but also cautious use of synchronization.

4. The callback function understands:

Not rigorous use of Ajax: Ajax submitted a request, such as to request an action, this time Ajax with this action said, elder brother you help me to do a thing Bai (I give you an address, you go to help me get a thing, and then give me), Then action agrees and finishes processing the business. At this point, action wants to tell Ajax what you asked me to do, and I'm ready for what you and I want, but how can I give it to you??

①: Do you want to go back and tell Ajax what you asked me to do, and I'm going to give it to Ajax? Do you want to make a request to ask for this thing again? In that case, how does the request know what was requested and how to get what? Just like Ajax is calling his friend Ajaxbbbb to help him get to action, but this action again how to tell this ajaxbbbb say where the things, you come to take. This and how to inform AJAXBBBB, do not have to make a request, this request asked him where to put things? This is not an infinite loop, so there is a callback function.

②: The function of the callback function is defined in Ajax, but there is an excuse to call someone else. For example, if the action completes the requested business, it invokes the Ajax success callback function, passes the data back to Ajax, and then success the callback function to process the data.

It's like this: Ajax thinks it's just not working, it's annoying. So he spent a big price, bought a pickup truck, this car is the Ajax, and then every time Ajax called action, he just told action to do, and then at home waiting, action done, just go to the Ajax truck, put things on the load, Send the past to Ajax. This car is a callback function, he belongs to the requesting party, and call him is the requested party, because the callback function is in the request side of the body, the requester can know that can access the function, you can get the information inside the function.

③: To help with memory, in a word. -------A object has 2 methods, one for sending the request to B, and the other for completing the request to send the information and data. A sends a request, B receives and completes, B calls the callback function in a, and a executes the callback function.

In fact, this B calls a callback function in a is very not rigorous or even wrong, because the purpose of B is to return the message and data to a, a, a, just say the data as a parameter of the callback function, such as a to execute the callback function. There's a lot of detail in this process. I just understand for everyone.

I just tried to explain my understanding. There is the wrong place to see, as for some very fine and very fine source code, the process of such analysis can be Baidu, these online a lot of.

Some understanding-filters, interceptors, Ajax commits do not jump after, document.location.href invalid, callback function.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.