How do I encode JSON in PHP via jQuery Ajax post data?

前端 未结 5 803
南旧
南旧 2021-01-31 00:16

I have an HTML form and send data to php file when hitting submit button.

$.ajax({
    url: \"text.php\",
    type: \"POST\",
    data: {
        amount: amount,         


        
5条回答
  •  梦谈多话
    2021-01-31 00:55

    You cannot directly insert a JSON object to a dom. JSON object toString() method will always give u [object object], that is why you are getting this. You ve to parse the data by using JSON.stringify(data) or you have to run $.each(data,function(val){ $("#result").append(val) }).

提交回复
热议问题