Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,932
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts

    Forms plugin – how to handle AJAX response?

    OK, never worked with AJAX form submission before but now’s the time. I have a form in an overlayed div which should not reload the page on submit. Therefore I’m using the form plugin to do the submission via AJAX (with the ajaxForm() function). Usually (without JS) the form would reload the page with the success message in it. The problem is now that the PHP script that processes the form (and on which I have no influence) returns the entire page as HTML result into the overlayed div and I just need the success message. How would I filter the result that is returned by AJAX?
    Last edited by VIPStephan; 07-24-2011 at 05:12 PM. Reason: resolved

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Not used ajaxForm(), so I don't know if it works in the same way, but using straightforward ajax(), retrieving an html page that includes an element with, say, #message, containing the result of submitting a form then:

    Code:
      ...
      success: function(data){
    	var message = $('#message',data).html();
            ...
    will allow the message to be retrieved.

  • Users who have thanked SB65 for this post:

    VIPStephan (07-24-2011)

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,932
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    Thank you very much. I haven’t quite understood the details of that operation but it’s working well (also with the plugin as the process of sending is the same).

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    You're welcome. From the jQuery page:

    By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the $() function.
    - so in your example the context becomes the ajax response.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •