Answers for "send array ajax php"

PHP
0

send array ajax php

var array = [1,2,3,4]; //array que deseo enviar

$.ajax({
          type: "POST",
          url: ...,
          data: {'array': JSON.stringify(array)},//capturo array     
          success: function(data){

        }
});

<php
$data = json_decode($_POST['array']);
var_dump($data);
?>
Posted by: Guest on September-16-2021
0

ajax pass array to php

const data = JSON.stringify([{a: 1}, {a: 2}, {a: 3}]);

const promise = $.ajax({
  type: "POST",
  url: "my-url/some-endpoint",
  data,
});

promise.done((response) => {
  console.log('Success');
  // Remember to parse your JSON string
  const stuff = JSON.parse(response);
});

promise.fail((response) => {
  console.log('Failed', response);
});

promise.always(() => {
  console.log('Complete');
});
Posted by: Guest on August-26-2021

Browse Popular Code Answers by Language