Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ajaxRequest(formId,savingText,success){
- $form = $("#"+formId+"Form")
- var originalButtonText = $form.find(".saveButton").html();
- var data = disableForm(formId,savingText); //returns $(form).serialize();
- $.ajax({
- url: 'actions/actions.php?section='+formId,
- type: 'POST',
- dataType: 'json', //NOTE THE JSON HERE
- data: data,
- success: function(response, textStatus, XMLHttpRequest){
- if (!response || response.status != 'success'){
- enableForm(formId, originalButtonText);
- ajaxError(); //this will do something like alert('there was an error')
- return false;
- }else if (response.status == 'success'){
- //YOU SHOULD WORK HERE:
- //start by doing console.log(response)
- //so you can view the structure of ur response array
- enableForm(formId, originalButtonText);
- if (response.message){
- alert( response.message)
- }
- eval("success_"+formId+"(response)");
- }
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- enableForm(formId, originalButtonText);
- alert('there was an error');
- console.log(XMLHttpRequest);
- return false;
- }
- });
- }
Add Comment
Please, Sign In to add comment