April 26, 2011
JQuery load at display page
Question by cosma
I’m newbie on web technologies and particular on jQuery so my question can be stupid.
What I want is to call a particular file (using .get or .post jQuery) when I click on some link and also load that file into browser. Also, the browser address should point to that file. This is what I have tried:
$('#my_link').click(
function(event){
event.preventDefault();
$.get("index.php", function(data){
$(document).html(data);
});
}
);
P.S.
I’m using .get/.post because I want to send some param. to that page (index.php), param. used to fill some fields.
Answer by Starx
I will suggest you, to try .load()
method instead. It also provides options for sending params.
Here is an example based on the question.
$('#my_link').click(function() {
$('#mydiv').load ("index.php", { param1: val1, param2: val2 }, function) {
alert('loaded');
});
});
I would suggest to load the contents on a division rather than the document itself.