使用jquery封装好的ajax

简单的使用jQuery的ajax

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jquery-ajax</title>
</head>
<body>
<input type="button" value="点击" id="btn">
<div id="showInfo"></div>
<script type="text/javascript" src="js/jquery-1.11.2.js"></script>
<script type="text/javascript">
    $(function(){

        $("#btn").click(function(){
            $.ajax({
                url:"01jquery.php",//一个用来包含发送请求的URL字符串。
                dataType:"script",//放回值的类型,HTML、text、json、、、
                type:"get",
                success:function(data){//请求成功后的回调函数
                    // $("#showInfo").html(data)
                    data;
                
                },
                error:function(e){
                    console.log(e);
                }
            });
        });



    });

</script>
</body>
</html>

 

01jquery.php
<?php
// 可以放字符串、HTML标签、JavaScript、只不过ajax的dataType值修改一下就可以了
//$tag ="hello ajax";
//$tag = '<div>水果</div><div>水果</div><div>水果</div><div>水果</div><div>水果</div><div>水果</div><div>水果</div><div>水果</div>';
$tag = 'alert(123);';
echo $tag;

?>

 

posted @ 2020-05-11 07:21  三线码工  阅读(390)  评论(0编辑  收藏  举报