Ajax parse json string is returning undefined,

后端 未结 2 1018
独厮守ぢ
独厮守ぢ 2021-01-25 20:13

I am sending a post data to get a json string back:

My JSON string:

{\"error\":false,\"success\":\"Added Website\",\"website_id\":\"12\"         


        
相关标签:
2条回答
  • 2021-01-25 20:48

    Try parsing your json string to a json object to get your values:

    data = JSON.parse(data);
    
    0 讨论(0)
  • 2021-01-25 20:50

    You haven't provided a dataType in your $.ajax, so AJAX treats the response as a string, not an object. So, inside the success function, do this first:

    success: function(data) {
      data = JSON.parse(data);
    
    0 讨论(0)
提交回复
热议问题