0

我有一个 php 页面,我会向另一个页面发送一个 jquery ajax 请求以发送电子邮件。这个新页面接受一个参数,然后执行查询 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;'; ?>

这是脚本

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

如何传递给 div“客户”的数据值?

4

4 回答 4

0
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");
                } 
        }
});
}
于 2011-09-23T14:19:42.470 回答
0
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");
                    } 
            }
    });
}
于 2011-09-23T14:20:53.630 回答
0

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

在 PHP 上:

$varName= $_POST['varName'];

对于更简单的 sintax,您可以使用它(相同):

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

    }catch (e){
        alert("correggi");
    } 
});
于 2011-09-23T14:23:16.103 回答
0

我希望这对你有用...

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

}

可以访问尽可能多的参数。

于 2011-09-23T14:47:05.883 回答