Ext.Ajax.request and Formpanel.getform (). Differences between submission methods of Submit two

Source: Internet
Author: User
Tags json

Ext.Ajax.request and Formpanel.getform (). Submit () The similarities and differences of two submitting methods:

1, the same point:

A) are used in the form of asynchronous submissions;

(b) The default is to submit the data using the Post method;

2, different points:

A the request method cannot use the Waitmsg property to set the information that is displayed during the wait response process, and this setting is available when the Submit method is submitted (you can see the effect, and the preceding is not available to see the effect being set);

b The request method must be manually organized and then used as the value of the parameter named params to be submitted to the server, and the Submit method organizes all input elements in the form to be submitted;

C when the request method is submitted, two parameters (Response,option) are passed in the callback function, which is the requested response object. The server's response information to the request can be obtained by its ResponseText property (that is, Response.reponsetext can get the string returned by the server), the second parameter is the submitted parameter object, which is generally not needed, and if you want to read the response information returned, first use the Ext.decod The E method converts its Resonsetext property value to a JSON object before it can be read; If the server side returns a JSON-formatted string: {success:true,msg: ' sample '}, then the client reads this information: VAR Returnresult = Ext.decode (Response.responsetext); alert (returnresult.msg); The callback function argument is (form,action), and if you want to read the response information, you just need to access the action object's Result property, like the same return information above, Read Example: alert (action.result.msg); However, it is important to note that when the network data transfer fails or the information is lost, the message returned by the server may not be fetched in the action, that is, the result does not necessarily have the MSG attribute. If it is accessed without judgment, an exception may be thrown;

D when the request method commits, the callback function executes in success:function () regardless of whether the success property in the returned JSON result is true, so in this case The failure callback method is executed only if there is a network error, the server is not connected, or the response page (404) must be success to result.success in the body of the method, and the Submit method returns the result if success True, the success:function is executed automatically, and if it is false, the failure:function is executed, so there is no need to determine in the inside whether success is true or false, and, as with request, When a network error or other unknown error occurs, failure:function is also executed;

Note: The reasons for this result are not difficult to understand, because in the 3rd mentioned above, the result of the request is obtained in the form of a string, which means that Ext does not parse it, so it cannot recognize the success or failure of the returned result, but brings back a string. When the Submit method commits, the returned Action.result object has resolved the response information, it can read the value of the success attribute in it, so it can perform the corresponding callback method according to the different success properties.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/ajax/

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.