I want to load a dynamic content to specific div name with multiple querystring from a menu.
Example dynamic menu link
index.php?tag=2
index.php?category=1&tag=2
index.php?category=2&tag=2&location=3
Example query process in PHP for link index.php?category=1&tag=2
$tag = intval($_GET['tag']);
$cat = intval($_GET['category']);
if(isset($tag) && isset($cat)) {
$select = $db->query("SELECT * FROM table WHERE cat=".$cat." AND tag=".$tag."");
... // fetch results
}
Question – With jQuery how to tell user clicked the link then send the callback to PHP process & show the results in the specific div name without refresh the page.
Let me know
Description
You have to create another php page that returns data in json format for the given substring. Your substring is dynamic so you have to get the substring from another element. I suggest a
<input type="hidden" value="YourQueryString"/>, its simple. You can put the element next to your link and get the value usingjQuery.val().Then you use
jQuery.ajax()/jQuery.get()orjQuery.post()in your index.php to get the data from that page / script. (jQuery.get()andjQuery.post()usesjQuery.ajax()internally)In the callback method of jQuery ajax you grab the data and build the html from it.
After that you can use jQuery.html() to set the data to your div.
Sample
html / php
jQuery
Update
Alternatively your php page can return html (simple page) for your query string. This is easier than build html in the
jQuery Ajax Callback. If this is done you can do thisMore Information
Documentation
Tutorials