ajax 发布整数和字符串数组

ajax post array of integers and string

本文关键字:字符串 数组 整数 布整数 ajax      更新时间:2023-09-26

我必须将整数数组和带有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 超级全局简单地检索数据。

// 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'];