Packy
Packy

Reputation: 3573

adding php response with ajax

I am getting some text from a php file by using ajax like so:

var oReq = new XMLHttpRequest(); //New request object
  oReq.onload = function() {

      console.log(this.responseText); 
      $('#twitterFeed').append(this.responseText);
  };
  oReq.open("get", "library/twitter.php", true);
  //                               
  oReq.send();

And it works just fine, adding the text to a div set up in the HTML file. The issue is I am using jticker to scroll the text but when I load the text via AJAX it wont scroll. If I paste the text in the div manually it will. I suspect since the text is being loaded in, the jticker.js is not appending the necessary classes to the div to make it scroll.

Upvotes: 1

Views: 35

Answers (1)

Ben Cole
Ben Cole

Reputation: 1897

You need to call jTicker on the element every time the contents change because it probably re-measures the element when you call $('.ticker').jTicker();

Example:

var oReq = new XMLHttpRequest(); //New request object
oReq.onload = function() {

    console.log(this.responseText); 
    $('#twitterFeed').append(this.responseText);

    // ADD THIS:
    $('.ticker').jTicker();

};
oReq.open("get", "library/twitter.php", true);
//                               
oReq.send();

Upvotes: 1

Related Questions