php抓取网页json数据(类似:UncaughtTypeErrortosearchfor‘’inJSONstring前端jsamp;php笔记正文)

优采云 发布时间: 2021-12-20 18:11

  php抓取网页json数据(类似:UncaughtTypeErrortosearchfor‘’inJSONstring前端jsamp;php笔记正文)

  类似:Uncaught TypeError:无法使用‘in’操作符在JSON字符串中搜索‘’前端js&php笔记

  身体:

  在html页面中,通过$.get()方法请求php页面,回调函数返回json数据,但是获取不到数据点中的数据,代码如下:

  js 代码:

  $("#button1").click(function(){

$.get("index.php",{username:$("#username").val(),password:$("#password").val(),tel:$("#tel").val()},function(data,textStatus){ //get方法请求数据

$("#response").html("用户名:"+data.name+"

密码:"+data.pwd+"

手机号码:"+data.tell);

alert(data); //能够显示数据

})

})

  php 代码:

  运行后:

  能够返回数据

  

  无法检索返回的数据

  

  解决方案:

  创建一个对象,将json数据转换成一个对象

  

  ajaxData=$.parseJSON(data) //将json数据转换为js对象

  注意:

  无法在程序中运行,在程序中运行时无法解释php页面,必须在appserv程序下的www文件夹下运行(运行时不能是ftp地址,而是像“:82” /unit07/index.html”地址)

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线