Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a PHP page into a div with jQuery and AJAX?

I am trying to write a function that will call getproduct.php?id=xxx when clicked. I can get the innerHTML portion to appear, but how do I also call the php page that actually does the work?

var id = id;
document.getElementById("digital_download").innerHTML = 
    "Downloading...Please be patient. The process can take a few minutes."; 
url = getproduct.php?id=id;
like image 280
Refiking Avatar asked Jul 08 '13 04:07

Refiking


Video Answer


2 Answers

you can call or load php page inside a div using this line as :-

$("#content_div").load("ajax/page_url.php");

the "ajax/page_url.php" its a relative path of php file.

so here you can replace it with external url as well.

please share you knowledge if i am wrong.

like image 150
Praveen Sharma Avatar answered Oct 05 '22 03:10

Praveen Sharma


You can do it with jQuery for example.

var id = 1;
$('#digital_download').html('Downloading...'); // Show "Downloading..."
// Do an ajax request
$.ajax({
  url: "getproduct.php?id="+id
}).done(function(data) { // data what is sent back by the php page
  $('#digital_download').html(data); // display data
});
like image 45
neumino Avatar answered Oct 05 '22 04:10

neumino