Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Parameters to a jQuery 'Load'

Tags:

jquery

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?

like image 804
JasonMHirst Avatar asked Jun 20 '11 11:06

JasonMHirst


People also ask

How use jQuery load method?

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.

What is the use of load () function?

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.

How to load HTML content into div using jQuery?

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.

How do I only load part of a page in HTML?

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.


1 Answers

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 :)

like image 93
Prasad Chavan Avatar answered Oct 10 '22 05:10

Prasad Chavan