weixin_33744854 2016-10-31 08:03 采纳率: 0%
浏览 36

按钮不触发Ajax

I have a form which submits elements to the database via AJAX, the problem that i am having is that when i click on the submit button it does nothing, it doesn't call the ajax request or anything.

HTML

  <div class="list">
    <input type="hidden" id="id" value="" />
    <div class="item">
        <label>Name</label>
        <input type="text" id="name" value="" />
    </div>
    <div class="item">
        <label>Number</label>
        <input type="text" id="number" value="" />
    </div>
    <div class="item">
        <label>Address</label>
        <input type="text" id="address" value="" />
    </div>
     <div class="item">
        <label>Price</label>
        <input type="text" id="price" value="" />
    </div>
     <div class="item">
        <label>Deposit</label>
        <input type="text" id="deposit" value="" />
    </div>
     <div class="item">
        <label>Product</label>
        <input type="text" id="product" value="" />
    </div>
     <div class="item">
        <label>Payment Type</label>
        <input type="text" id="payment_type" value="" />
    </div>
     <div class="item">
        <label>Deal Date</label>
        <input type="text" id="deal_date" value="" />
    </div>
     <div class="item">
        <label>Install Date</label>
        <input type="text" id="install_date" value="" />
    </div>
     <div class="item">
        <label>Installed</label>
        <input type="text" id="installed" value="" />
    </div>
     <div class="item">
        <label>Notes</label>
        <textarea name="notes" cols="" id="price" rows=""></textarea>
    </div>
     <div class="item">
        <label>Contract Received</label>
        <input type="text" id="contract_recieved" value="" />
    </div>
    <div class="item">
        <input type="button" id="insert" class="button button-block" value="Insert" />
    </div>

Javascript

  $(document).ready(function() {
    $("#insert").click(function() {
        var name = $("#name").val();
        var number = $("#number").val();
        var address = $("#address").val();
        var price = $("#price").val();
        var deposit = $("#deposit").val();
        var product = $("#product").val();
        var payment_type = $("#payment_type").val();
        var deal_date = $("#deal_date").val();
        var install_date = $("#install_date").val();
        var installed = $("#installed").val();
        var notes = $("#notes").val();
        var contract_recieved = $("#contract_recieved").val();
        var dataString = "name=" + name + "&number=" + number + "&address=" + address + "&price=" + price + "&deposit=" + deposit + "&product=" + product + "&payment_types=" + payment_types + "&deal_date=" + deal_date + "&install_date=" + install_date + "&installed=" + installed + "&notes=" + notes + "&contract_recieved=" + contract_recieved + "&insert=";
        if ($.trim(title).length > 0 & $.trim(duration).length > 0 & $.trim(price).length > 0) {
            $.ajax({
                type: "POST",
                url: "http://http://www.domain.com/test6/services/insert.php",
                data: dataString,
                crossDomain: true,
                cache: false,
                beforeSend: function() {
                    $("#insert").val('Connecting...');
                },
                success: function(data) {
                    if (data == "success") {
                        alert("inserted");
                        $("#insert").val('submit');
                    } else if (data == "error") {
                        alert("error");
                    }
                }
            });
        }
        return false;
    });
});
  • 写回答

3条回答 默认 最新

  • weixin_33738578 2016-10-31 08:17
    关注

    In url use "https://www.domain.com/test6/services/insert.php" Also some of the variables you are using are undefined fix them for example payment_types and duration.

    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条