Using ajax to call php and return multiple variables?

后端 未结 5 839
既然无缘
既然无缘 2021-02-04 22:30

I am trying to use javascript to call a php script which then will return multiple variables back to my javascript so I can manipulate them.

This is my JS.



        
5条回答
  •  滥情空心
    2021-02-04 22:47

    You can go for Json in PHP and javascript if you want array in response for a ajax request

    PHP Code

    $fileId,"num1"=>1,"num2"=>2));
    ?>
    

    Js Code

    jQuery.ajax({
        type: "GET",
        url: 'test.php',
        dataType: "json",
        success: function(response) {
            console.log(response);
            alert(response.num1);
        }
    });
    

提交回复
热议问题