Search code examples
ajaxjqueryjquery-posthttp-post

send parameter with jquery ajax


I've a php page and I would to send a jquery ajax request to another page for sending email. This new page accept one parameter and then it executes query ecc...

 <div id="customer" name="customer" style="visibility: hidden;"><?php echo $customer; ?></div>
<?php echo '<input id="pulsante" type="image" src="includes/templates/theme485/buttons/english/button_confirm_order.gif" onclick="inoltra();">&nbsp; &nbsp;'; ?>

this is the script

function inoltra(){
var jqxhr = $.ajax({
       type: "POST",
       url: "../gestione_di_canio/services.php",
       datatype: "json",
       data: ??????????????
       async:true,
       success:function() {
           try{
               alert("ok");

            }catch (e){
                alert("correggi");
                } 
        }
});
}

how can I pass to data value of div "customer"?


Solution

  • On data: { varName: $('#customer').html() }

    on Php:

    $varName= $_POST['varName'];
    

    For a simpler sintax, you use this (it the same):

    $.post("../gestione_di_canio/services.php", { varName: $('#customer').html() } )
    .success(function() { 
        try{
            alert("ok");
    
        }catch (e){
            alert("correggi");
        } 
    });