weixin_33675507 2012-06-09 19:02 采纳率: 0%
浏览 77

jQuery Ajax HTML替换

My question is simple I receive string and a number but only number show up How I can display both?

     $.ajax({
            type: "POST",
            url: "data.php",
            data: "act="+nr,
            success: function (result) {

                var arr = JSON.parse(result);

                if ($.isArray(arr) == true) {
                    $.each(arr, function (i, n) {
                        $('#s_main #s_info').html("<p>+" + n + "</p>")
                    });

                }

            }
        })
    }); //ends here

my php:

$act = $_POST['act'];

$output =array();
$act2 = "TXT!!!";
array_push($output,$act);

echo json_encode($output);

By the way when i use append instead of html the result is correct but it will stack on and not delete the previous data

  • 写回答

1条回答 默认 最新

  • weixin_33699914 2012-06-09 19:05
    关注

    What you are getting in return is a JSON Object.

    if ($.isArray(arr) == true)
    

    This line shouldn't return true becuase an object is not an array. If the JSON.parse() did not work it will return a value that will equate to false. So you can simply test the returned object to see if it was successful.

    var jsonObj = JSON.parse(result);
    
    if (jsonObj) {
      $.each(jsonObj, function (index, value) {
        $('#s_main #s_info').html("<p>+" + value + "</p>")
      });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数