我是jQuery和Ajax的新手,但无论如何,我想知道,如果我能在使用jQuery显示PHP 0utput数据方面得到一些帮助。
这是我的html文件
<!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>
这是我简单的PHP文件page1.php:
<?php
echo "This is the sample data to be printed";
?>
有什么方法可以关联这两个文件,以便php文件的输出使用Jquery和Ajax显示在html文件中
答案 0 :(得分:0)
您已将// change non-opaque pixels to white
var imgData=ctx.getImageData(0,0,canvas.width,canvas.height);
var data=imgData.data;
for(var i=0;i<data.length;i+=4){
if(data[i+3]<255){
data[i] = 255 - data[i];
data[i+1] = 255 - data[i+1];
data[i+2] = 255 - data[i+2];
data[i+3] = 255 - data[i+3];
}
}
ctx.putImageData(imgData,0,0);
放在$("#btnLoad").click()
之外。更改脚本并将其移到内部,然后单击将起作用:
$(document).ready
答案 1 :(得分:-1)
从以下javascript代码替换您的javascript代码:
$(function(){
$("button").click(function(){
$("div").empty();
});
$("#btnLoad").click(function(){
$.ajax({
type: 'POST',
url: 'pager1.php',
success: function(data){
if(data != null) $("#content").text(data)
}
});
});
});