send array ajax php

Solutions on MaxInterview for send array ajax php by the best coders in the world

showing results for - "send array ajax php"
Dorothy
11 Sep 2017
1var array = [1,2,3,4]; //array que deseo enviar
2
3$.ajax({
4          type: "POST",
5          url: ...,
6          data: {'array': JSON.stringify(array)},//capturo array     
7          success: function(data){
8
9        }
10});
11
12<php
13$data = json_decode($_POST['array']);
14var_dump($data);
15?>
Vincenzo
04 Feb 2018
1const data = JSON.stringify([{a: 1}, {a: 2}, {a: 3}]);
2
3const promise = $.ajax({
4  type: "POST",
5  url: "my-url/some-endpoint",
6  data,
7});
8
9promise.done((response) => {
10  console.log('Success');
11  // Remember to parse your JSON string
12  const stuff = JSON.parse(response);
13});
14
15promise.fail((response) => {
16  console.log('Failed', response);
17});
18
19promise.always(() => {
20  console.log('Complete');
21});