$ (Document). ready (function (){ Var options = { Target: '# output1 ', // The data transmitted from the service is displayed inside the div. That is, ajax partial refresh BeforeSubmit: showRequest, // Processing before ajax submission Success: showResponse // Processing after processing }; $ ('# ShowDataForm'). submit (function (){ $ (This). ajaxSubmit (options ); Return false; // Very important. If it is false, it indicates no jump // Handle this page, that is, ajax. If it is not false, the traditional form jumps. }); }); Function showResponse (responseText, statusText, xhr, $ form ){ Alert (xhr. responseText + "=" + $ form. attr ("method") + 'status: '+ StatusText + '\ n \ nresponseText: \ n' + responseText ); // Xhr: indicates that you can use ajax to send a request again. // $ Form: the form object. It is a jquery object. // StatusText: status. If it succeeds, it is success. // ResponseText. The server returns a string (including html, not json, of course) } Function showRequest (formData, jqForm, options ){ // FormData is an array, which is the map array of the key values of each input. // This method is used to process and piece together strings. // FormData: The assembled form string, such as name = hera & password, // It is actually the key-value pair of input in each form, // If method = XXXX is added, it is equivalent to the data in ajax. Var queryString = $. param (formData ); Alert (queryString + "====" + formData. length ); For (var I = 0; I <formData. length; I ++ ){ Alert (formData [I]. value + "==================" + formData [I]. name ); } // JqForm, jquery form object Var formElement = jqForm [0]; Alert ($ (formElement). attr ("method ")); Alert ($ (jqForm [0]. name). attr ("maxlength ")); // It is very important. If true is returned, it indicates that you verify it before submitting ajax. // If the request is successful, the ajax form is submitted. // If the verification fails, non-true is returned and no submission is made. Return true; } |