Kai
Kai

Reputation: 277

AJAX/JQUERY - Split the returned data and place in two seperate divs

I am currently using the following code to run an AJAX query every 10 seconds to populate <div id="datacontainer"></div>

setInterval(function(){
$.ajax({
    url: "ajax.php",
    type: "GET", 
    cache: false}
).done(function(html) {
$( '#datacontainer' ).html( html );});},10000
);

I have now setup the ajax.php file to return a string that now contains the delimiter '----' that I want to split and populate two div's.

I want to split into data[] when split data[0] goes into <div id="nummessages"></div> and data[1] goes to <div id="datacontainer"></div>

How would this code need to be modified to achieve this?

Upvotes: 3

Views: 11294

Answers (1)

jingyinggong
jingyinggong

Reputation: 646

setInterval(function(){
  $.ajax({
      url: "ajax.php",
      type: "GET", 
      cache: false}
  ).done(function(html) {
    var divs = html.split('----');
    $( '#nummessages' ).html( divs[0] );
    $( '#datacontainer' ).html( divs[1] );
  });
},10000);

Upvotes: 12

Related Questions