0

I need to load a dynamic created javascript with PHP. Is there any good solution to load javascript creating by PHP after some ajax requests finished?

Thx in regards, i am searching for 2h in stackoverflow.

if i call .ajax function where html/js respone, jquery kills the js ;/

Wykk
  • 812
  • 6
  • 12
  • 1
    you can put the response in eval() – Voonic Sep 17 '13 at 08:49
  • works this only for js generated or if this result is with html too? – Wykk Sep 17 '13 at 08:58
  • You can generate an entire HTML block with `` and append it to your document, you can create actual JS and use `eval()` like @shadow said or you can just rethink your approach and create a system that receives data from PHP and acts upon it. – N.B. Sep 17 '13 at 08:59
  • 1
    @N.B. - thoughts I'd just mention that `` blocks do not generally execute when you add them to the document. I believe some libraries (Underscore?) do a bit of work to *simulate* this, by scanning for ` – cloudfeet Sep 17 '13 at 09:03
  • and what can i do then? a trigger event? – Wykk Sep 17 '13 at 09:06
  • @Wykk: Are you *actually* doing code-generation in PHP? That seems very bizarre. – cloudfeet Sep 17 '13 at 09:06
  • yes i use it for googleapi for my articles – Wykk Sep 17 '13 at 09:11
  • 1
    Do you want to receive a JSON response, and then make a separate request to get some JavaScript, or are you looking to *receive* JavaScript as a response, and execute it immediately? – cloudfeet Sep 17 '13 at 09:17
  • I get it to work, i will make a answer. – Wykk Sep 17 '13 at 09:27

1 Answers1

1
jQuery.ajax({
    type: 'POST',
    dataType: 'html',
    url: $url,
    success: function(result)
      { 
         result // html

         jQuery.ajax({
     type: 'GET',
     dataType: 'script',
         url: $url,
         success: function(result)
            { 
            //the result is js and is availble in browser if you return 
            //a function you can execute this now

            }
          });

      }
});

Hope someone find his answer here :) gl & hf & nice day

Wykk
  • 812
  • 6
  • 12
  • You should consider accepting your own answer. By that people can see the question is answered, and perhaps find the answer useful. – davidkonrad Sep 22 '13 at 03:07