dataType: “json” won't work

前端 未结 7 1461
面向向阳花
面向向阳花 2020-12-10 16:19

I\'m trying to send back multiple variables from a php file to ajax using json in an array. The code in the php file works perfectly and does everything with my database lik

7条回答
  •  半阙折子戏
    2020-12-10 17:08

    I believe if you use dataType you should be using contentType, "The official Internet media type for JSON is application/json".

    .ajax(
    {
     url: 'UpdateComments.php',
     type: 'POST',
     contentType: "application/json",//note the contentType defintion
     dataType: "json",
     data: 
     {
       type: "add",
       comment: $("#comment").val(),
       id: videoID  
     },
     success: function (data) 
     {
       //Get the data variables from json and display them on page
     }
    });
    

提交回复
热议问题