jquery ajax(3).post
.post返回文本数据
$(function(){
$("#send").click(function(){
$.post("post1.php", {
username : $("#username").val() ,
content : $("#content").val()
}, function (data, textStatus){
$("#resText").html(data); // 把返回的数据添加到页面上
}
);
})
})
php文件
<?php
header("Content-Type:text/html; charset=utf-8");
echo "<div class='comment'><h6>{$_REQUEST['username']}:</h6><p class='para'>{$_REQUEST['content']}</p></div>";
?>
.post 返回xml数据 $(function(){
$("#send").click(function(){
$.post("post2.php", {
username : $("#username").val() ,
content : $("#content").val()
}, function (data, textStatus){
var username = $(data).find("comment").attr("username");
var content = $(data).find("comment content").text();
var txtHtml = "<div class='comment'><h6>"+username+":</h6><p class='para'>"+content+"</p></div>";
$("#resText").html(txtHtml); // 把返回的数据添加到页面上
},"xml");
})
}) php 文件
<?php
header("Content-Type:text/xml; charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>".
"<comments>".
"<comment username='{$_REQUEST['username'] }' >".
"<content>{$_REQUEST['content']}</content>".
"</comment>".
"</comments>";
?>
.post 返回json数据实现
$(function(){
$("#send").click(function(){
$.post("post3.php", {
username : $("#username").val() ,
content : $("#content").val()
}, function (data, textStatus){
var username = data.username;
var content = data.content;
var txtHtml = "<div class='comment'><h6>"+username+":</h6><p class='para'>"+content+"</p></div>";
$("#resText").html(txtHtml); // 把返回的数据添加到页面上
},"json");
})
})
php文件
<?php
header("Content-Type:text/html; charset=utf-8");
echo "{ \"username\" : \"{$_REQUEST['username']}\" , \"content\" : \"{$_REQUEST['content']}\"}"
?>
.load注意是
$(function(){
$("#send").click(function(){
$("#resText").load("post1.php",{
username : $("#username").val() ,
content : $("#content").val()
})
})
})
<?php
header("Content-Type:text/html; charset=utf-8");
echo "<div class='comment'><h6>{$_REQUEST['username']}:</h6><p class='para'>{$_REQUEST['content']}</p></div>";
?>
jquery ajax(3).post的更多相关文章
- HTML&javaSkcript&CSS&jQuery&ajax(11)
1.localStorage 没有 时间的限制数据存储, sessionStorage 针对一个session的存储,首先检查浏览器是否支持对这两个的存储, ifI(type(Storage)!==& ...
- HTML&javaSkcript&CSS&jQuery&ajax(十)
HTML 1.SVG直接嵌入HTML网页 ,SVG 是使用XML描述2D图像的语言,Canvas通过JavaScript来绘制2D <svg xmlns="http://www.w3. ...
- HTML&javaSkcript&CSS&jQuery&ajax(五)
一.Framset标签定义了每个框架中的HTML文档, 1. <framset cols="25%,75%"> <frame src="frame_a. ...
- HTML&javaSkcript&CSS&jQuery&ajax(九)
一.HTML 1.单选按钮 <form action="><inpput type="radio" name="sex" value ...
- HTML&javaSkcript&CSS&jQuery&ajax(六)
一.HTML表单 1.<input type="text">定义文本输入的单上输入字段,<form> First name:<br> < ...
- jquery ajax (1)原始js 实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jquery ajax(5)form表单序列化
form表单序列化<script type="text/javascript"> $(function(){ $("#send").click(fu ...
- jquery ajax(4).getjson()
.getJSON()实例 .each()实例 $(function(){ $('#send').click(function() { $.getJSON('test.json', function(d ...
- jquery ajax (2)实例 .GET
1js 代码 $(function(){ $("#send").click(function(){ $.get("get3.php", { username : ...
随机推荐
- datagridview bindingsource刷新数据
调用bindindsource的ResetBindings() 方法
- Java---网络编程(1)
网络编程 相关基础概念 1.计算机网络与Internet 2.TCP/IP协议 3.Internet地址 - - -IP地址,形如xxx.xxx.xxx.xxx - - -域名系统.例如www.edu ...
- bzoj 2330 [SCOI2011]糖果(差分约束系统)
2330: [SCOI2011]糖果 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3574 Solved: 1077[Submit][Status ...
- linux 挂载ISO
首先,将作为源的iso的挂载到系统上. 代码如下: mount -o loop /xxx/xxx.iso /mnt/iso/ 其中/mnt/iso是事先在本地建立的文件夹. 然后将文件iso.repo ...
- Spring配置多个数据源
Spring 配置多数据源实现数据库读写分离 博客分类: Spring 数据库 现在大型的电子商务系统,在数据库层面大都采用读写分离技术,就是一个Master数据库,多个Slave数据库.Mast ...
- listview 遇到问题java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
开发的时候 遇到 java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 这个异常有时候会有,有时候正常 不太好捕捉 猜测 已经 ...
- Windows下Postgre SQL数据库通过Slony-I 实现数据库双机同步备份
一. 我们要实现的环境是windows xp.windows2003上安装Postgre SQL数据库,实现目的是两台数据库服务器进行数据库同步,即数据库同步更新.删除.插入等对数据库的操作. 二. ...
- CDH5 安装过程
一.环境 1.1 操作系统 $ cat /etc/redhat-release CentOS release 6.5 (Final) 1.2 Java环境 $ java -version java v ...
- Directx 3D编程实例:绘制可变速旋转的三角形
最近朋友建议我写一些关于微软云技术的博客留给学校下一届的学生们看,怕下一届的MSTC断档.于是我也觉的有这个必要. 写了几篇博客之后,我觉得也有必要把这一年的学习内容放在博客做个纪念,就这样写了本篇博 ...
- Toast的使用具体解释
Android中提供一种简单的Toast消息提示框机制,能够在用户点击了某些button后,提示用户一些信息,提示的信息不能被用户点击,Toast的提示信息依据用户设置的显示时间后自己主动消失.Toa ...