+ Reply to Thread
Results 1 to 5 of 5

Thread: Is this possible? (Ajax & JQuery Document Scope Problem)

  1. #1
    jason is offline Coder jason will become famous soon enough
    Join Date
    Apr 2008
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is this possible? (Ajax & JQuery Document Scope Problem)

    I am in the middle of developing something that is causing problems, most likely because it may be trying to stand on a shakey design (which I assumed would work, until now).

    Basically I have an XHTML (Strict) document, which is using a combination of JQuery + Ajax to load content in to certain div's based on some event handling I'm processing with JQuery. My problem is that the markup that is being loaded in to certain div's with Ajax calls contains elements which I need to do further event handling, and can't because it's out of scope of the document. The browser can see the markup (after the ajax call), but the document doesn't see it and therefore jQuery can't perform event handling on elements it cannot see unless they are in the same document.

    So far my page is constructed as follows:

    PHP document, generating XHTML (Strict) markup with document content. Amongst document content there are 2 div's, both of those div's are populated after ajax calls have been made to seperate php scripts for respective content. In the content that is returned to both divs, I want to be able to for example manipulate using jQuery an element in div(A) by clicking on an element in div(B).

    Is this possible? Is the architecture wrong?

    any help greatly appreciated

  2. #2
    jason is offline Coder jason will become famous soon enough
    Join Date
    Apr 2008
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah I found the problem. I needed to take a break from coding

    Solution
    1. Don't sit in front of your computer writing code with a complete disregard for the passage of time.
    2. Do take breaks so you don't end up making stupid design decisions
    3. Instead of placing the markup inside the ajax call, just place the initial markup structure in the php script, so the entire DOM structure is available
    4. Then using the ajax call, populate the necessary elements via jQuery.
    Sorry folks, false alarm. I am an idiot

  3. #3
    jason is offline Coder jason will become famous soon enough
    Join Date
    Apr 2008
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah-HA!, I'm not an idiot, but I am talking to myself in here a lot (hmmmm...)

    NEway, my "solution" didn't get me completely there, because I've learned a lesson today about the DOM, and using Ajax calls to update the contents of page containers. From my understanding (always open to correction), if you re-init the contents of a div, using an ajax call then the new content is not reachable from javascript code expressed on the host document.

    If I use PHP to fill a div with content, then later use ajax on that document to update the div, beyond that point in time the javascript (jQuery) code on that document will not be able to access the contents of of the updated div.

    Please help because I'm going out of my mind. (...clearly).

  4. #4
    jason is offline Coder jason will become famous soon enough
    Join Date
    Apr 2008
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey Jason, I think your problem has something to do with the need to rebind events to newly loaded elements via ajax.

    Frequently Asked Questions - jQuery JavaScript Library

    HTH

  5. #5
    jason is offline Coder jason will become famous soon enough
    Join Date
    Apr 2008
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cheers Jason

+ Reply to Thread

Similar Threads

  1. document root on nfs share
    By adm in forum Server / Technical Administration Tips and Queries
    Replies: 0
    Last Post: 01-05-2008, 02:27 PM
  2. PHP/AJAX based display problem.
    By ziycon in forum Coding Help
    Replies: 7
    Last Post: 06-03-2008, 08:42 AM
  3. jQuery background colour toggle
    By Goodshape in forum Coding Help
    Replies: 4
    Last Post: 16-12-2007, 08:54 PM
  4. AJAX PHP Books
    By louie in forum Coding Help
    Replies: 26
    Last Post: 29-08-2006, 03:00 PM

Visitors found this page by searching for:

Nobody landed on this page from a search engine, yet!
SEO Blog

Tags for this Thread

Posting Permissions

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

Search Engine Optimization by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64