SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    question pertaining to .load() and loading javascript

    When i load a page using the .load() funtion that page dosnt display javascript.

    example: googleads will not display via the new page that was loaded thru .load()




    Code:
    function updateElement(el_id, action) {
    	if (document.getElementById(el_id).innerHTML == ""){
         $('<div id="info" />').load('''+action+' #ghgh', function()

  2. #2
    SitePoint Enthusiast TriLLi's Avatar
    Join Date
    Feb 2010
    Location
    BiH, Bugojno
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    i have one solution for you.
    You can return result as JSON
    example
    Code JavaScript:
     { javascript: 'script content', html: 'html' }

    and when you receive response you can execute script, but first of all you need to append you html than call script, reason for this is because script might need something from returned HTML

    You can execute your script like this
    Code JavaScript:
    var s = 'alert("senad");';
    s += 'alert("meskin");';
    s += 'var a = 10; var b = 13;';
    s += 'var c = a+b;';
    s +='alert(c);'
    eval(s);

    Full example:
    Code JavaScript:
    $.post('/info/getinfo/',
            {
                mode: 'sample of sending var trough post',
            }, function(data){            
               $('#targetdiv').html(data.html);
               eval(data.javascript);
            }, 'json');

    or you can create custom javascript that will be executed when loading is done.
    http://www.wiseblog.info
    Programmers don't die, they just GO SUB without return.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •