不报错 也什么都不显示

来源:1-4 使用get()方法以GET方式从服务器获取数据

qq_哒哒_14

2018-06-01 16:53

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>使用get()GET方式从服务器获取数据</title>

<script type="text/javascript" src="lib/jquery-3.3.1.min.js">

</script>

</head>

<!--

    使用get()方法时,采用GET方式向服务器请求数据,并通过方法中回调函数的参数返回请求的数据,

    它的调用格式如下:

$.get(

    "发送的请求地址" ,

    要发送的数据 key/value , 

回调函数 ,

"返回内容格式,xml, html, script, json, text "

);


    -->

<body>

<div>

<div>

<span>我的个人资料</span>

<span>

<input type="button" value="加载" id='jia' />

</span>

</div>

<ul></ul>

</div>

<script type="text/javascript">

$(function (){

$('#jia').bind('click',function(){

var $this = $(this);

$.get('new_file.php',function(date){

$this.attr('disable','true');

$('ul').append("<li>我的名字叫:"+date.name+"</li>");

$('ul').append("<li>男朋友对我说:"+date.say+"</li>");

//返回内容格式,xml, html, script, json, text 

},"script");

});

});

</script>

</body>

</html>


info.php文件


<?php

echo json_encode(array("name"=>"土豪","say"=>"咱们交个朋友吧"));

?>


写回答 关注

2回答

  • merrymai
    2018-08-05 23:01:28

    new_file.php ???你文中不是这样:

    info.php文件


    <?php

    echo json_encode(array("name"=>"土豪","say"=>"咱们交个朋友吧"));

    ?>


  • qq_哒哒_14
    2018-06-01 17:00:40

    $.get('new_file.php',function(date){

    $this.attr('disable','true');

    $('ul').append("<li>我的名字叫:"+date.name+"</li>");

    $('ul').append("<li>男朋友对我说:"+date.say+"</li>");

    //返回内容格式,xml, html, script, json, text 

    },"script");   加粗部分 只要改成json就不显示  改成其他的 就 undefined


jQuery基础(五)一Ajax应用与常用插件

如何用jquery实现ajax应用,加入学习,有效提高前端开发速度

69095 学习 · 400 问题

查看课程

相似问题