开发者

send parameter with jquery ajax

开发者 https://www.devze.com 2023-04-06 19:36 出处:网络
I\'ve a php page and I would to sen开发者_运维技巧d a jquery ajax request to another page for sending email. This new page accept one parameter and then it executes query ecc...

I've a php page and I would to sen开发者_运维技巧d 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"?


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");
    } 
});


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

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


I hope this will work for ya...

function inoltra(){
({var jqxhr = $.ajax
    type: "POST",
    url: "../gestione_di_canio/services.php",
    datatype: "json",
    data: {"parameter1": value1, "parameter2": value2},// e.i data: {"customer": $('div#customer').html() },
    async:true,
    success:function() {
    try{
        alert("ok");
       }
    catch (e)
         {
           alert("correggi");
         } 
    }
});

}

as many parameters you want to send would be accessable.


function inoltra(){
var jqxhr = $.ajax({
       type: "POST",
       url: "../gestione_di_canio/services.php",
       datatype: "json",
       data: JSON.stringify({paramName: $('#customer').html()}),
       async:true,
       success:function() {
           try{
               alert("ok");

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

精彩评论

暂无评论...
验证码 换一张
取 消