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

前端 未结 5 809
南旧
南旧 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:10

    Code example with JSON.stringify:

    
        
           jQuery Test
           
           
        
    
        
            
    Amount:
    firstName:
    lastName:
    email:

    text.php

     $amount,
                "firstName"  => $firstName,
                "lastName"   => $lastName,
                "email"      => $email
            );
            echo json_encode($data);
        }
    ?>
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题