Jump to content
php.lv forumi

ajax pieprasītajā failā javascript


ray

Recommended Posts

problēma ir tāda, ka ar ajax tiek uztaisīts pieprasījums un tiek pieprasīts fails, kurš satur arī javascript kodu, bet šis javascript nezin kapēc netiek izpildīts un nedarbojas tas tiek vnk ignorēts. pārejais kas tur ir (teksts) tiek attēlots. ir kādam risinājumi, kā likt tam javascript strādāt?

Link to comment
Share on other sites

eval() nestrādās, ja responsā būs arī html kods

 

var izmantot kaut ko šitādu :

function execScripts(text) {
   var search = text;
   var script;

   while(script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i))
   {
     search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);

     if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break;

     block = search.substr(0, search.indexOf(RegExp.$1));
     search = search.substring(block.length + RegExp.$1.length);

     eval(block);
   }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...