posting strings and array to php with ajax not working

pass array in ajax javascript
how to pass array data in jquery ajax
how to pass array in jquery ajax get request
send array in ajax get request
jquery ajax pass array to controller
send array of objects via ajax to php
how to get array response in jquery ajax
how to send multiple array in ajax

nothing complicated here. just posting the data using ajax and its not working..

     var ttc=$("#lblTot").val();
      var tva=$("#prixTva").val();

      var net=$("#prixNet").val();
      var taxes=[ttc,tva];
      var build="testing1212";



      $.ajax({
        type:'POST',
        url:'passerCommande.php',
         data: {
            prices : net,
            taxes : taxes,
            build : build,
          },
        });

and here is my php file

  <?php
    error_reporting(0);

   $itemPrices=$_POST['prices'];
    $taxes=$_POST['taxes'];
    $build=$_POST["build"];

    $date=date("Y-m-d h:i");

    echo "build : ".$build;
    ?>

i tried to "echo" the build but its empty.

You have 3 errors in your JS function : - "type" instead of "method" (see http://api.jquery.com/jquery.ajax/) - you have an extra comma after "build" in the data values - you have an extra comma after the data values

JS is not as permissive as PHP

$.ajax({
    method:'POST',
    url:'passerCommande.php',
    data: {
        prices : net,
        taxes : taxes,
        build : build
    }
});

And you should use var_dump() instead of echo function

Passing JavaScript Array To PHP Through JQuery $.AJAX, AJAX.Sometimes you need to process an array of data through php. So we need to pass the whole array in a variable. This method you need to convert the JavaScript array to JSON String. Your email address will not be published. Loading About Me · Contact Me · Terms & Privacy. Copyrights  hello guys, I'm passing data to a jquery/ajax that in turns pass the data to a php program. this works fine when i post singular values, but i cannot get it to work when passing an array of data

Are you sure it's call after page loaded if yes please check console by inspect elements and check errors and send me or if you don't know please run

$(document).ready(function (){
     // your code.....
});

addslashes - Manual, It only escapes according to what PHP defines, not what your database driver defines. Which means that if they pass in a string that includes a "\'", you expand it to "\'''" (an Recursive Function to add slashes with posted array. do in PHP (for example, when returning an Ajax result, inside a json string value, or when  nothing complicated here. just posting the data using ajax and its not working.. posting strings and array to php with ajax not working. Ask Question

You need to stringify your output: $json = json_encode($build); echo $json;

urlencode - Manual, This function is convenient when encoding a string to be used in a query part of a URL writen, you can have problems with encode strings with special characters to flash. able to pass this source code to the ajax form submit function by using php urlencode : Makes an valid html request url by parsing the params array That is why we dedicate a whole chapter to working with strings in PHP. PHP string literal. A string literal is the notation for representing a string value within the text of a computer program. In PHP, strings can be created with single quotes, double quotes or using the heredoc or the nowdoc syntax.

Jquery/ajax post array data - JavaScript, I'm passing data to a jquery/ajax that in turns pass the data to a php Is it not possible to loop through my array when posted to my jquery/ajax  I just spent hours to fix a similar issue and the problem was the max_input_vars = "1000" limit of php.ini. Be sure to check php.ini values of upload_max_filesize, post_max_size and max_input_vars. Exceeding one will results with an empty $_POST array.

Can't get a JSON object in response to an Ajax request with wp_ajax , I have a problem with WordPress and Ajax. the object/array with get_posts() results is returned correctly and not as a string: posts = $.ajax({ type: 'GET', url: ajaxurl, async: false, dataType: 'json', data: textStatus, errorThrown ) { console.​log( 'Could not get posts, server response: ' + Almost there with your PHP function. The $.ajax submission reaches the target page OK, but the data that should have been sent with the post seems to get lost along the way. $_POST is always empty. The submitHandler for jquery.validate has the following code;

Easy Way to Post Multiple JavaScript Values to PHP Using jQuery , Maybe it is an array of numbers or simple point objects. to list out a ton of fields in some long data string that you give to a jQuery $.ajax() call. your data passing problems and gives you some great ideas to efficiently pass  AJAX was made popular in 2005 by Google, with Google Suggest. Google Suggest is using AJAX to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions. Start Using AJAX Today. In our PHP tutorial, we will demonstrate how AJAX

Comments
  • fixed all that , var_dump($build) gave me a result of null
  • why the code is not working after fixing what you mentioned ?
  • Can you post a var_dump($_POST) ?
  • actually my code is inside a function i call onclick of a button. and no i have no errors
  • Ok add a ,success: function (data){ console. log(data); } in ajax function
  • should i put the button that calls the function wich has the ajax code inside a form ? cause i am doing that. i removed "taxes" nothing changed.
  • i got "null" result