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

前端 未结 5 797
南旧
南旧 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 01:13

    Try adding

    header('Content-type: application/json');
    

    At the top of your PHP script and see what you get back

    Hope that helps!

    Edit: Forgot to mention you should access your values like so: data.amount

提交回复
热议问题