php+jquery+ajax简单Ajax调用示例

128 篇文章 1 订阅
14 篇文章 0 订阅

html网页:


<!DOCTYPE HTML>

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    $(function(){
        //按钮单击时执行
        $("#testAjax").click(function(){
              
              //Ajax调用处理
            var html = $.ajax({
               type: "POST",
               url: "add.php",
               data: "name=garfield&age=18",//在php中data: "name=$tt&id=$id&content="+text,
               async: false


            }).responseText;
            $("#myDiv").html('<h2>'+html+'</h2>');
         });
    });
</script>    
</head>
    <body>
        <div id="myDiv"><h2>通过 AJAX 改变文本</h2></div>
        <button id="testAjax" type="button">Ajax改变内容</button>
    </body>

</html>



add.php

<?php
$msg='Hello,'.$_POST['name'].',your age is '.$_POST['age'].'!';
 echo $msg;
?>

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值