gpt4 book ai didi

javascript - ajax post 整数和字符串数组

转载 作者:行者123 更新时间:2023-12-02 16:36:34 25 4
gpt4 key购买 nike

我必须使用 ajax 将整数数组和字符串值发送到 php。如何做到这一点以及如何在 php 端获取这些值?

// values to be send
var nums = [1,2,3,4];
var method = "delete";

$.ajax({
url: "ajaxcalls.php",
type: "GET",
dataType: "json",
data: ???,
contentType: 'application/json; charset=utf-8',
});

// ajaxcalls.php
<?php
???
?>

最佳答案

只需将对象中的数据传递给 $.ajax,jQuery 就会为您序列化数据。
在 PHP 中,您可以通过 $_GET super 全局简单地检索数据。

// values to be send
var nums = [1,2,3,4];
var method = "delete";

$.ajax({
url: "ajaxcalls.php",
type: "GET",
data: {"nums": nums, "method": method}

});
<?php
$numArray = $_GET['nums'];
$method = $_GET['method'];

关于javascript - ajax post 整数和字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com