又一个ajax实例,配合jQuery
<!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8"><meta name="renderer" content="webkit"><!--360,以webkit内核进行渲染--><meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"><!--以最新内核进行渲染。--><meta http-equiv="Cache-Control" content="no-siteapp"/><!--百度禁止转码--><title>moyu demo</title><meta name="keywords" content="demo 测试 魔芋"><meta name="description" content="魔芋的测试示例"><meta name="author" content="魔芋,15000720652@163.com,http://www.cnblogs.com/moyuling/"><meta name="robots" content="index,follow"><!--定义网页搜索引擎索引方式--><meta name="viewport" content="width=device-width, initial-scale=1.0"><script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script><style></style></head><body><button>moyu</button><p></p><script> $("button").click(function(){ $.post(‘http://localhost/moyu.php‘,{ name:"nihao", city:"monkey"},function(data, status){ $("p").html("Data: "+ data +"<br>"+"Status: "+ status);})});</script></body></html><?php$name = isset($_POST[‘name‘])? htmlspecialchars($_POST[‘name‘]):‘‘;$city = isset($_POST[‘city‘])? htmlspecialchars($_POST[‘city‘]):‘‘;echo ‘Dear ‘. $name;echo " ";echo ‘Hope you live well in ‘. $city;?>
原文:http://www.cnblogs.com/moyuling/p/5272503.html