I have some script on my page which is:
$('#divMenuHolder').load('../menu.html');
However I also need to be able to pass some parameters which are acted on the menu.html page.
I've tried the following:
$('#divMenuHolder').load('../menu.html?opt1=test&opt2=test2');
However when I come to get the parameters using the following function:
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
It returns nothing because it's trying to get the parameters of the page itself, and not the page I'm loading into DIV.
Can anyway assist in guiding me to what I want please?
jQuery - AJAX load() Method The load() method loads data from a server and puts the returned data into the selected element. Syntax: $(selector).load(URL,data,callback); The required URL parameter specifies the URL you wish to load.
The Load function initializes a database and loads it from an input data file. It can be used for initial loading of a database, as part of a database reorganization, or for reloading a database after changing the DBD definition.
To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.
Method 1: Using HTML: One can use the anchor tag to redirect to a particular section on the same page. You need to add ” id attribute” to the section you want to show and use the same id in href attribute with “#” in the anchor tag.
This works for me
$('#semester').load("restricted/getSemester.php?courseid=" + $("#course").val());
where #course
is id of input field.
OR
$('#subject').load("restricted/getSubject.php?courseid=0&semester=0");
I hope this helps u :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With