这是jquery(ajax)-> php响应

  {"errorInfo":["23000",1062,"Duplicate entry 'blahblah' for key 'sn'"]}


如何使用jquery仅打印“键'sn'的重复条目'blahblah'”

 success: function (html) {
   $("#notification").fadeIn("slow")
   .text(html); //Duplicate entry 'blahblah' for key 'sn'? html->errorInfo[2]?
  }


谢谢

更新:

它是标准的PDO错误功能

     catch(PDOException $e) {
          print json_encode($e);
      }


这样打印出来:

   {"errorInfo":["23000",1062,"Duplicate entry 'SDAAASSASADASADASDAS' for key 'sn'"]}


更新:

我在另一侧更改它,在源头上,我使用

   print json_encode($e->errorInfo[2]); instead of print json_encode($e)

最佳答案

正确的语法是html.errorInfo[2]html["errorInfo"][2]等效。如果可以的话(在这种情况下),习惯上使用第一种形式。

在使用时,为什么不还将参数从html重命名为更合适的名称,例如result

关于json - 打印json数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9846677/

10-11 22:25
查看更多