2011-09-23 76 views
0

我有一個PHP頁面,我會發送一個jQuery Ajax請求到另一個頁面發送電子郵件。這個新頁面接受一個參數,然後執行查詢ECC ...發送參數與jQuery的AJAX

<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的「客戶」數據的價值?

回答

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

}

的許多參數要發送將accessable。