【问题标题】:send parameter with jquery ajax使用 jquery ajax 发送参数
【发布时间】:2011-09-23 14:14:51
【问题描述】:

我有一个 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 "customer" 的数据值?

【问题讨论】:

    标签: ajax jquery jquery-post http-post


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:
      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");
                          } 
                  }
          });
      }
      

      【讨论】:

        【解决方案3】:

        我希望这对你有用...

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

        }

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

        【讨论】:

          【解决方案4】:
          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");
                          } 
                  }
          });
          }
          

          【讨论】:

            猜你喜欢
            • 2012-03-08
            • 2015-10-26
            • 1970-01-01
            • 2011-02-23
            • 2013-09-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-09-14
            相关资源
            最近更新 更多