Mysql
 sql >> Datenbank >  >> RDS >> Mysql

So übergeben Sie mit jQuery mehrere Variablen an PHP

POSTEN SIE AJAX-ANFRAGE mit JS / JQUERY. Das Folgende ist die Syntax, die ich für alle meine AJAX-Aufrufe verwende.

var first = 'something';
var second = 'second';
var third = $("#some_input_on_your_page").val();


///////// AJAX //////// AJAX //////////
    $.ajax({
        type: 'POST',
        url:  'page_that_receives_post_variables.php',
        data: {first:first, second:second, third:third},
        success: function( response ){
            alert('yay ajax is done.');
            $('#edit_box').html(response);//this is where you populate your response
        }//close succss params
    });//close ajax
///////// AJAX //////// AJAX //////////

Code für die PHP-Seite page_that_receives_post_variables.php

<?php
$first = $_POST['first'];
$second = $_POST['second'];
$third = $_POST['third'];

echo 'now do something with the posted items.';
echo $first; //etc...
?>