dataType: “json” won't work

前端 未结 7 1448
面向向阳花
面向向阳花 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条回答
  •  -上瘾入骨i
    2020-12-10 16:58

    I wouldn't use the dataType if it is causing you issues, also I've personally not used an object as the data value before maybe that has something to do with it?

    Anyway I've tweaked the main ajax routine I hope this helps.

    $.ajax(
    {
       url: 'UpdateComments.php',
       type: 'POST',
       data: 
       {
          type: "add",
          comment: $("#comment").val(),
          id: videoID  
       },
       success: function (response) 
       {
           //Get the data variables from json and display them on page
           var data = $.parseJSON(response);
           alert(data.id);
       }
    });
    

提交回复
热议问题