views:

32

answers:

1

Hi there

I am using the ajax form plugin to handle my ajax submissions, like so..

 // Submit Form New User
  $('#setAdminUser').ajaxForm({
   beforeSubmit : validateForm,
   success: ajaxSuccess
     });

    // Ajax success callback
  function ajaxSuccess(){
  // Do processing here
           // Create div, containing the response from my ajax call
           var str = ''
           str += '<div id="recordCreated">'
           str += '<h2> Record ' + data + 'd</h2>'
           str += '</div>'

           // Add div to container on page
           $("#userAdded").html(str)
  }

What I am looking to do, is grab the response data from my ajax call so I can use it in my function ajaxSuccess, as sgiwb above. Is there anyway to achieve this?

Many thanks

+1  A: 

You could add the response as parameter to the function:

function ajaxSuccess(response) {
    // use the response here
}

Quote from the documentation:

success: Callback function to be invoked after the form has been submitted. If a 'success' callback function is provided it is invoked after the response has been returned from the server. It is passed the responseText or responseXML value (depending on the value of the dataType option).

Darin Dimitrov
Yes, this has worked..thanks very much
namtax