ajax 第一个简单程序
2013-01-13 01:20
417 查看
//////////////////////////////////////////pull.html
<html>
<body>
<h1> the result of pulled news:</h1>
<script type="text/javascript" src="jquery.js"></script>
<input type="button" class="pull" value="abutton"/>
<table border=1>
<tr><td>news from server:</td></tr>
<tr id="pullnews"></tr>
</table>
<script type="text/javascript">
$(".pull").click(function(){
$.ajax({
url:"handlePull.php",
data:"newsid=123", //attention:paramname=value 不是paramname:value
type:'post',
dataType:'json',/////atten:如果输入json object,这里却写成text,则object解析出undefined错误
success:function(result){
//attention: 获得参数是 object.paramname ,不能被双引号引入。
pullnews.innerHTML="<td>"+result.title+"</td><td>"+result.digest+"</td>";
alert("ajax recv:"+result);
}});
});
</script>
</body>
</html>
////////////////////////////////////////////////////////////////////////////////handlePull.php
<?php
class news{ public $newsid,$title,$digest;}; $news=new news;
$news->newsid=$_REQUEST["newsid"];
$news->title="中日建交n年";
$news->digest="小泉纯一郎参拜靖国神社,被中国人民强烈谴责";
echo json_encode($news);
?>
<html>
<body>
<h1> the result of pulled news:</h1>
<script type="text/javascript" src="jquery.js"></script>
<input type="button" class="pull" value="abutton"/>
<table border=1>
<tr><td>news from server:</td></tr>
<tr id="pullnews"></tr>
</table>
<script type="text/javascript">
$(".pull").click(function(){
$.ajax({
url:"handlePull.php",
data:"newsid=123", //attention:paramname=value 不是paramname:value
type:'post',
dataType:'json',/////atten:如果输入json object,这里却写成text,则object解析出undefined错误
success:function(result){
//attention: 获得参数是 object.paramname ,不能被双引号引入。
pullnews.innerHTML="<td>"+result.title+"</td><td>"+result.digest+"</td>";
alert("ajax recv:"+result);
}});
});
</script>
</body>
</html>
////////////////////////////////////////////////////////////////////////////////handlePull.php
<?php
class news{ public $newsid,$title,$digest;}; $news=new news;
$news->newsid=$_REQUEST["newsid"];
$news->title="中日建交n年";
$news->digest="小泉纯一郎参拜靖国神社,被中国人民强烈谴责";
echo json_encode($news);
?>
相关文章推荐
- 写一个ajax程序就是如此简单
- 第一个简单的jQuery程序
- 使用Ajax long polling实现简单的聊天程序
- Java第一个简单的程序
- 我的第一个AJAX程序
- 第一个简单的web程序的例子
- [Android] 002_第一个简单的Android程序
- 我的第一个AJAX程序
- Intellij Idea12第一个安卓程序开发(HelloWorld)及简单讲解Android
- 深入了解汇编的第一个简单程序(对初学者很重要)
- SBT(Scala Build Tool)系列教程-使用sbt构建第一个简单的HelloWorld程序
- 第一个简单的程序——Struts 2 官方文档翻译(Struts 2官方文档中文版)
- Spring -- 第一个简单的Spring程序
- 写一个ajax程序就是如此简单
- 一个简单的AJAX实现,基于C#的ASP.Net,包括服务器端的程序代码
- 《Go语言入门》第一个Go语言Web程序——简单的Web服务器
- MFC入门(一)-- 第一个简单的windows图形化界面小程序(打开计算器,记事本,查IP)
- Opencv第一个简单程序
- [导入]写一个ajax程序就是如此简单
- \t\t简单的Ajax小程序2