Tuesday, 15 January 2013

json - How to only append once when loading in html Ajax -


I'm loading the content from the JSON file in the lightbox. The light box opens the second HTML in that HTML I add data loaded from the JSON file to various elements. However, when I open the lightbox, I want to add once, how can I do this?

  $ (document) .on ('click', '.mch-overlay-info', function (e) {e.preventDefault (); var href = $ (this) .attr ('Href'); $ ('# mch-overlay-content') .HTML (''); $ ('# mch-overlay') .FadeIn (300); $ ('# mch-overlay-content') Load (href, function () {showInfo ();});}); Function showInfo () {$ (".txt3 start"). Append (data [lang] ['start page'] ['text3']); $ ("Begin .txt4"). Append (data [lang] ['start page'] ['text4']); $ ("Start .txt5"). Append (data [lang] ['start page'] ['text5']); }   

I am assuming your problem that every time they add it click We do? Two options:

  1. Do not add it. To set up the content and change the old content, simply $ (). Use HTML () .
  2. Control with one variable

      var hasBeenAppended = false; // etc ... function showInfo () {if (HasBeenAppended) {hasBeenAppended = true; $ ("Start Txt3"). Append (data [long] ['start page'] ['text3']); $ ("Begin .txt4"). Append (data [lang] ['start page'] ['text4']); $ ("Start .txt5"). Append (data [lang] ['start page'] ['text5']); }}      

No comments:

Post a Comment