Introduce the difference between the AJAX submission URL and the AJAX submission form

Source: Internet
Author: User

  This article is mainly about the AJAX submission URL and the difference between the Ajax submission form, the need for friends can come to the reference, I hope to help you.

1:ajax constructs a URL that passes parameters to data and cannot be used for form submission.   Example:     code is as follows:          function createhtml (ID) {              $ ("#reloading"). Show ();               //EDIT_BG is a div, displayed when submitted, This allows the background page to not operate.               $ ("#edit_bg"). Show ();              $.A Jax ({              type: "POST",              URL: " Pageaction!createhtml.action ",              data:" id= "+id,              success:function (data) {              $ ("#reloading"). Hide (); &nbs P             $ ("#edit_bg"). Hide ();              if (data = = ' True ' {              alert ("successful operation.") ");               }else{                      alert ("Operation failed , please contact the administrator! ");                     }                     }//Operation successful operation                    } ;                      }    2:ajax Submission form, which is very useful for large data transfer, such as user registration, letter Very large, with Ajax submission form, the page is more beautiful but, for the Ajax submission form, we have to introduce a JS, that is: Jquery.form.js "  Example:   code as follows:     function UploadFile () {          $ ("#reloading"). Show ();        $ ("#edit_bg"). Show () ;         //FORM1 for table single-name         $ ("#form1"). Ajaxsubmit ({      &N Bsp Type: "POST",        success:function (data) {        $ ("#reloading"). Hide (); nbsp       $("#edit_bg"). Hide ();        if (Data.indexof ("true")!=-1) {        alert ("Operation succeeded.") ");       }else{        alert (data);         alert (" Operation failed , please contact the administrator! ");       }         }//Operation successful operation          };            }    3:2 The AJAX submission form can operate correctly, but there is a problem with the data returned and the page does not get the results. The following code corrects the AJAX submission form     code as follows:     function SubmitForm () {  $ (' #form1 '). Ajaxsubmit ( Ajaxoptionsnew);          }       var ajaxoptionsnew = {          &N Bsp       Beforesubmit:fn_check_form,                   Success : Showresponse,                   URL: "Costation!save2.action",   &NBS P           &nbsp   Error:function (xmlresponse) {                      alert ( Xmlresponse.responsetext);                        alert (' Operation failed! ');                     //window.location.reload ();    & nbsp            }              };         function fn_check_form () {      if ($ ("#Name"). val () = "") {  alert ("Man cannot be empty" ;  $ ("#Name"). Focus ();  return false; }         }      function s Howresponse (responsetext) {                 try{                 //alert (responsetext);                  & nbsp  if (ResponseText = = ' true ') {                           alert (' Operation successful! ');                          window.location.reload () &nb Sp                    }              &NB Sp      else if (responsetext = ' paramfalse ')                   &N Bsp  {                      alert ("Required parameters cannot be empty!")                      }            &NB Sp        else if (responsetext = = ' Timeerror ')                 &NB Sp    {                       alert ("Departure time is not greater than reimbursement time!");             &nbsp        }                     else{  &NBSP ;                       alert (' Operation failed! ');                        //  window.location.reload () &nbs P                                   & nbsp  }catch (e) {alert (e.message);}          }      
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.