Sending PHP json_encode array to jQuery

前端 未结 4 1440
攒了一身酷
攒了一身酷 2020-12-10 22:07

ok, i guess I need help ! I searched with every keyword I could think off, but I still cant figure out, please help. Am more of a php guy, and I\'ve just started with jQuery

4条回答
  •  甜味超标
    2020-12-10 22:54

    All you gotta do, its tell the Ajax call that you're receiving data type "json". In other words...

    $.ajax({
       url: "external_file",
       method:"post",
       dataType: "json",  // **************** Note dataType****************
       success:function(response){
           console.log(response)
           // Response will be a javascript array, instead of a string.
       },
       error: function(){
           alert('something went wrong.')
       }
    })
    

提交回复
热议问题