Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load content with Jquery together with sending variable in to it

Tags:

jquery

I have a variable - x in jquery, I am loading a php part in div block and I need sent that variable to it.

So -

$(document).on('click','#link',function () {
var x=5;
$("#block").load("file.php");
});

In result I am still in the same page.I just need to have variable x in it.

I think about to use GET method or XMLHttpRequest but I don't want to another page, I just need to load a php part in block.

like image 293
ZeroVash Avatar asked Dec 20 '22 03:12

ZeroVash


1 Answers

One solution is to send data as second argument:

$(document).on('click', '#link', function() {
  $("#block").load("file.php", {
    x: 5
  }, function(res) {
    //your callback 
  });
});

References

.load()

like image 147
Alex Char Avatar answered Jun 01 '23 11:06

Alex Char