Irish SEO,  Marketing & Webmaster Discussion

 

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

This is a discussion on Is this possible? (Ajax & JQuery Document Scope Problem) within the Coding Help forums, part of the Webmaster Help category; I am in the middle of developing something that is causing problems, most likely because it may be trying to ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Calendar Search Today's Posts Mark Forums Read

  #1 (permalink)  
Old 30-06-2008, 05:17 PM
Coder
 
Join Date: Apr 2008
Posts: 57
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jason will become famous soon enough
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 30-06-2008, 06:03 PM
Coder
 
Join Date: Apr 2008
Posts: 57
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jason will become famous soon enough
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 30-06-2008, 07:19 PM
Coder
 
Join Date: Apr 2008
Posts: 57
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jason will become famous soon enough
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).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 01-07-2008, 02:06 PM
Coder
 
Join Date: Apr 2008
Posts: 57
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jason will become famous soon enough
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 01-07-2008, 02:07 PM
Coder
 
Join Date: Apr 2008
Posts: 57
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
jason will become famous soon enough
Default

Cheers Jason
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
ajax, document, jquery, problem, scope

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


Sponsored links

Pepperjam Network
Paid On Results www.zanox.com


All times are GMT +1. The time now is 06:36 PM.


Powered by: vBulletin Version 3.8.2, Copyright ©2000 - 2009, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.3.0

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