ajax pass array to php

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

showing results for - "ajax pass array to php"
Luis
21 Nov 2019
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});