tags:

views:

78

answers:

2

I am using jQuery Form Plugin

It is working fine as I have it now.

I want to add some functionality. After the form submits the plugin is returning back responseText (see above link). I am updating one div with this link. What If I want to update multiple div's...with different messages. Basically, I'm wondering if there is a way to get 'multiple' responseText(s).

A way around is to put all I want in one responseText and then somehow break it (using substring) and update multiple divs?

Also, How do we add some content to the div using jQuery?

A: 

This can modify your element's innerHTML:

var elem = document.getElementby(whatever) 
$(elem).innerHTML = ...

or

$("#elemId").innerHTML = ...

If you dispatch several ajax requests, you can get multiple responseTexts back. Consider that if you are doing these requests to the same server, it's probably less traffic to just send one request, and have the server compile the answer XML from several different scripts, rather than several xmlHTTPRequests, each with different callbacks.

ryansstack
So you are suggesting that my server-side should return one xmlHTTPRequest but with xml object ?
A: 

If you return something like this from the server:

<div id="message1">My Message 1</div>
<div id="message2">My Message 2</div>

You can let jQuery parse the responseText by setting the html of a dummy <div> to the response text:

var $response = $('<div/>').html(responseText);
var message1 = $('#message1', $response).html();
var message2 = $('#message2', $response).html();

And then you can add the messages to whatever <div> you want to:

$('#some_notification_div').html(message1);
$('#some_other_notification_div').html(message2);
Paolo Bergantino
When I do this. I am putting $response in an alert box. however. $response is shown as object and so message1 is always null.