1

私の問題を厳密に Ajax で解決しようとして失敗した後、JQuery に移行しました。残念ながら、私は JQuery の理解が限られており、誰かが私が間違っていることを教えてくれることを望んでいました。私はこの問題に数日を費やしましたが、本質的にどこにも行きませんでした!

理論上の私のタスクは単純です。やりたいことは、HTML ドロップダウン メニューの値を取得し、ドロップダウン メニューの適切な行で php 関数を呼び出すことだけです。PHP 関数 print_wp_cart_button_for_product は、カートに追加ボタンを出力します。この関数は、製品配列の項目に対応する行を介して呼び出されます。

<TR>
   <TD>
   <select id="productcategory1" name="productcategory1" onchange="productchange()">
    <option value="$">--Please Select--</option>
    <option value="1">Product # 1 - $1.99</option>
    <option value="2">Product # 2 - $1.99</option>
    <option value="3">Product # 3 - $9.99</option>
    <option value="4">Product # 4 - $9.99</option>
  </select>
  </TD>
  <TD>    

  <div id="test">
  </div>

  <script type = "text/javascript">
  function productchange() 
  {
      var currentrow = $('#productcategory1').val();
      //alert(currentrow);

      $.ajax({
        type: "GET",
        url: "http://www.example.com/wp-content/themes/themeX/order.php",
        data: "rownum=" + currentrow,
        success: function(currentrow){
            $("#test").html(currentrow);
            }});
      return false;
  }
  </script>

  <?php $rownum = $_GET['test']; ?>
  <?php echo print_wp_cart_button_for_product($products[$rownum]["Product"], $products[$rownum]["Price"]); ?>
  </TD>
  </TR>  

Order.php:

<?php
$rownum = $_GET['rownum'];
echo "Row Number = $rownum";
?>
4

1 に答える 1

0
$.ajax({
        type: "GET",
        url: "http://www.example.com/wp-content/themes/themeX/order.php",
         data: {'rownum': currentrow},
        success: function(currentrow){
            $("#test").html(currentrow);
            }});

Try that. Also

<?php $rownum = $_GET['test']; ?>

You dint close the last php and started another..that gives error in first place

Everything is fine in your codes..as far as i see. Have you included jquery library file??

于 2012-12-28T18:44:32.497 に答える