Reputation: 97
I'm totally new to AJAX, so I'm sorry if the question turned out to be too stupid or anything.
Alright then, here goes...
assuming that http://example.com/index.php
file have the following content:
<HTML>
<HEAD>
<title>Ajax Test</title>
</HEAD>
<BODY>
<!-- Other contents which don't need to change -->
<a class="puke" href="#">Button</a>
<div class="rainbow"><?php echo mt_rand(0,100); ?></div>
<!-- Other contents which don't need to change -->
</BODY>
</HTML>
I want to make it so that whenever a.puke
is clicked, only the content of div.rainbow
will get refreshed.
How can I achieve such result?
thank you.
Upvotes: 0
Views: 44
Reputation: 4436
Since your are new to AJAX, here is the code example for ajax and php- ajax php . Refer this link
$.ajax({
url: "http://example.com/index.php",
type: "GET",
cache: false,
success: function(data){
$("div.rainbow").html(data);
}
});
Upvotes: 1
Reputation: 587
you can use .responseText
document.getElementsByClassName("puke").onclick = updateDiv();
function updateDiv() {
upd=new XMLHttpRequest();
upd.open("GET","test.php?action=something" , false);
upd.send();
console.log(upd.responseText);
document.getElementsByClassName("rainbow").innerHTML=upd.responseText;
}
this is how you get contents of test.php?action=something and put it to
div.rainbow
Upvotes: 0