Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jQuery中解析JSON数据并在textfield中显示_Javascript_Jquery_Json - Fatal编程技术网

Javascript 在jQuery中解析JSON数据并在textfield中显示

Javascript 在jQuery中解析JSON数据并在textfield中显示,javascript,jquery,json,Javascript,Jquery,Json,我将以JSON格式打印test.php中的响应数据,以便在特定字段上打印 $.ajax({ type: 'POST', url: 'test.php', data: data, success: function(response) { var result = $.parseJSON(response); $(document).ready(function(){ $("#test").click(function(){

我将以JSON格式打印
test.php
中的响应数据,以便在特定字段上打印

$.ajax({
    type: 'POST',
    url: 'test.php',
    data: data,
   success: function(response) {
   var result = $.parseJSON(response);

   $(document).ready(function(){
      $("#test").click(function(){
          $("#bemail").val(result.email);//when i prints only result than it displays [object object]

      });
   });
   }
});

您正在AJAX成功处理程序中调用document.ready(),该处理程序不会被调用,因为AJAX调用不会再次调用文档加载,DOM已经加载,并且在页面会话的生命周期中只加载一次

这就足够了

          $.ajax({
                type: 'POST',
                url: 'test.php',
                data: data,
               success: function(response) {
                  var result = JSON.parse(response);
                  $("#bemail").val(result[0].email); //after you explained the JSON response
               }
            });

像这样试试。您必须将ajax放入
$(文档)中。准备好了吗

$(document).ready(function(){
$.ajax({
                type: 'POST',
                url: 'test.php',
                data: data,
               success: function(response) {
                  var result = JSON.parse(response);
                  $("#bemail").val(result.email);
               }
            });

});

你的代码完全错了,应该是

function displayEmail() {
  $.ajax({
    type: 'POST',
    url: 'test.php',
    data: data,
    success: function(response) {
      var result = $.parseJSON(response);
      //Just Print the Result in Console using console.log(result)
      $("#bemail").val(result.email);
    }
  });
}
$(document).ready(function() {
  $("#test").click(function() {
    displayEmail();
  });
});

你需要展示一下response@Param您将得到什么样的响应作为输出?jquery是一个DOM解析器,而不是JSON解析器。您可以使用jQuery进行查询,但XML可能更好?
$(文档)。准备好了吗?我认为这永远不会触发..result.email是一个json对象。放置JSON.stringify以查看此对象中的数据。即使它会干扰
DOM
document.ready()
,也不会触发。@textbox值更新后,而不是在成功事件时,RayonDabre DOM将被干扰。你在说什么?
document.ready()
DOM
操作的关系是什么?@RayonDabre“即使它会干扰DOM”你的这部分评论就是我所指的。成功事件不会干扰DOM。我从未提到成功回调后会更新DOM…我的观点是DOM更新和
document.ready()
没有关系。。你在误导OP。。