Guest User

Untitled

a guest
May 18th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.12 KB | None | 0 0
  1. function ajaxRequest(formId,savingText,success){
  2.     $form = $("#"+formId+"Form")
  3.     var originalButtonText = $form.find(".saveButton").html();
  4.     var data = disableForm(formId,savingText); //returns $(form).serialize();
  5.  
  6.     $.ajax({
  7.         url: 'actions/actions.php?section='+formId,
  8.         type: 'POST',
  9.         dataType: 'json',   //NOTE THE JSON HERE
  10.         data: data,
  11.         success: function(response, textStatus, XMLHttpRequest){
  12.             if (!response || response.status != 'success'){
  13.                 enableForm(formId, originalButtonText);
  14.                 ajaxError();    //this will do something like alert('there was an error')
  15.                 return false;
  16.             }else if (response.status == 'success'){
  17.                 //YOU SHOULD WORK HERE:
  18.                 //start by doing console.log(response)
  19.                 //so you can view the structure of ur response array
  20.                 enableForm(formId, originalButtonText);
  21.                 if (response.message){
  22.                     alert( response.message)
  23.                 }
  24.                 eval("success_"+formId+"(response)");
  25.             }
  26.         },
  27.         error: function(XMLHttpRequest, textStatus, errorThrown) {
  28.             enableForm(formId, originalButtonText);
  29.             alert('there was an error');
  30.             console.log(XMLHttpRequest);
  31.             return false;
  32.         }
  33.     });
  34. }
Add Comment
Please, Sign In to add comment