jquery json post返回整个页面html
我有两个页面,一个将值发布到另一个页面,然后它进行 mysql 查询并将数据返回到第一个页面。如果我使用jquery json post,而不是jquery ajax post,如何取回整个页面? (我想取回mysql查询结果)。谢谢。
<html>
<head>
<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
$("#submitbutton").click(function(){
$.ajax({
url: "m2.php",
dataType: "json",
data: "number1="+$('#number1').val(),
success: function(json){
//$("#result").html(json.number1);// original json data get, it can success.
$("#result").load('m2.php');//jquery load only load an empty page...
}
});
});
});
</script>
</head>
<body>
<input name="number1" id="number1" value="today" type="text" />
<input type="submit" value="Calc" id="submitbutton" name="submitbutton"/>
<div id="result"></div>
</body>
</html>
<?php
$db = @mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
mysql_select_db("contact",$db);
$number1 = $_GET['number1'];
$arr = array();
$arr['number1'] = $number1;
//echo json_encode($arr); // original json encode data, back to the first page
$searchword = json_encode($arr);
$result = mysql_query("SELECT * FROM msg where title like '%$searchword%' Order By id DESC Limit 0,10");
while($row = mysql_fetch_array($result)){
echo $row['name'];// This is what I want get the data.
}
?>
I have two pages, one posts value to another, then it makes a mysql query and returns the data to the first one. If I use jquery json post, instead of jquery ajax post, how to get back the whole page back? (I want get back the mysql query results). Thanks.
<html>
<head>
<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type="text/javascript">
$(document).ready(function(){
$("#submitbutton").click(function(){
$.ajax({
url: "m2.php",
dataType: "json",
data: "number1="+$('#number1').val(),
success: function(json){
//$("#result").html(json.number1);// original json data get, it can success.
$("#result").load('m2.php');//jquery load only load an empty page...
}
});
});
});
</script>
</head>
<body>
<input name="number1" id="number1" value="today" type="text" />
<input type="submit" value="Calc" id="submitbutton" name="submitbutton"/>
<div id="result"></div>
</body>
</html>
<?php
$db = @mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
mysql_select_db("contact",$db);
$number1 = $_GET['number1'];
$arr = array();
$arr['number1'] = $number1;
//echo json_encode($arr); // original json encode data, back to the first page
$searchword = json_encode($arr);
$result = mysql_query("SELECT * FROM msg where title like '%$searchword%' Order By id DESC Limit 0,10");
while($row = mysql_fetch_array($result)){
echo $row['name'];// This is what I want get the data.
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
在你的 html 页面中使用 json 解码值。
Try this:
In your html page use json-decoded value.