I'm kinda new to jQuery and Ajax, but anyways, I was wondering, if I could get some help in displaying the PHP 0utput data using jQuery.
This is my html file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing Out in PHP!!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type = "text/javascript" src="jquery1.js"></script>
<script type = "text/javascript">
$("#btnLoad").click(function(){
$.ajax({
type: 'POST',
url: 'page1.php',
success: function(data){
if(data != null) $("#content").text(data)
}
});
});
$(document).ready(function(){
$("button").click(function(){
$("div").empty();
});
});
</script>
</head>
<body>
<div id="content" style="height:100px; width:250px;background-color:yellow">
This is some text
<p>This is a paragraph inside the div.</p>
</div>
<input type="button" id="btnLoad" value="Load" />
<button>Clear Contents </button>
</body>
</html>
This is my simple PHP file page1.php:
<?php
echo "This is the sample data to be printed";
?>
is there any way I can associate the two files, so that the output from php file is displayed in html file using Jquery and Ajax