I need to create a page that will load divs from an external page using jQuery and AJAX.
I came across some good tutorials, but they are all based on static content, my links and content are generated by PHP.
The main tutorial in which I base my code is:
http://yensdesign.com/2008/12/how-to-load-content-via-ajax-in-jquery/
The exact function I need is as follows:
- The main page contains a permanent list containing some links containing the parameter.
- After clicking, the link passes the parameter to the external page.
- The external page filters the entries by parameter and fills the div with the results.
- The new div contains a new set of links with new parameters.
- The outer div is loaded under the main pages of the first div.
- Then the process can be repeated, creating a chain of divs under each other.
- The last div in the chain will then direct to a new page, matching all previously used queries.
I can handle all the work of PHP with filling the div on the main and external pages.
This is the part of jQuery and AJAX that I'm afraid of.
$(document).ready(function(){ var sections = $('a[id^=link_]'); // Link that passes parameter to external page var content = $('div[id^=content_]'); // Where external div is loaded to sections.click(function(){ //load selected section switch(this.id){ case "div01": content.load("external.php?param=1 #section_div01"); break; case "div02": content.load("external.php?param=2 #section_div02"); break; } });
The problem I ran into is getting JQuery to pass dynamically generated parameters to an external page and then fetch a new div.
Currently, I can only do this with static links (as mentioned above).
source share