-1

我正在尝试将一些数据发布到 Django 应用程序,但每个变量都工作正常,除了一个..

这是我的表格:

<div class="subfield">
        <span>
        Found a coupon for <b><span style="color:#d95b44;" id="Store_Name">{{ storeData.0.storeName }}</span>?</b>
        Enter the details below to share with other users
        </span>
        <form>                              
        <br>
        <label for="user">Coupon code :</label>
        <input type="text" id="coupon_Code" maxlength="100"  />
        <br>
        <label for="user">Discount :</label>
        <textarea rows="2" cols="19" minlength="15" id="coupon_Discount"></textarea>
        <br>
        <div id="buttn">&nbsp;&nbsp;
        <button type="button" style="margin:0;padding:0;" onclick="javascript:submitCoupon();">Submit Coupon</button>
        </div>
        </form>
    </div>

我的 JavaScript 是:

<script type="text/javascript">
        function submitCoupon()
    {   
        var store_Name = document.getElementById('Store_Name').value;
        var couponCode = document.getElementById('coupon_Code').value;
        var couponDiscount = document.getElementById('coupon_Discount').value;
        var data =  {"storeName":store_Name,"couponCode":couponCode,"couponDiscount":couponDiscount,
                    csrfmiddlewaretoken:'{{ csrf_token }}'};
        alert(store_Name);
        $.ajax({ // create an AJAX call...
            data: data, // get the form data
            type: "POST", // GET or POST
            url: "/submit_coupon/", // the file to call
            dataType: "json",
            success: function(response) { // on success..
             alert("done");

            }
        });
    }
</script>

在三个变量中couponCode并且couponDiscount正在工作但没有store_Name...我尝试更改变量名称,id 但没有任何工作每当我试图提醒store_Name我变得未定义...并且控制台也没有显示错误...

4

1 回答 1

2
<div class="subfield">

    <form>  
       <span>
        Found a coupon for <b><span style="color:#d95b44;" id="Store_Name">{{  storeData.0.storeName }}</span>?</b>
        Enter the details below to share with other users
       </span>                            
         <br>
       <label for="user">Coupon code :</label>
       <input type="text" id="coupon_Code" maxlength="100"  />
        <br>
       <label for="user">Discount :</label>
       <textarea rows="2" cols="19" minlength="15" id="coupon_Discount"></textarea>
         <br>
       <div id="buttn">&nbsp;&nbsp;
          <button type="button" style="margin:0;padding:0;" onclick="javascript:submitCoupon();">Submit Coupon</button>
       </div>
   </form>
</div>

表单中使用的Store_Name 的跨度,然后它可以正常运行

于 2013-05-03T07:02:55.150 回答