gpt4 book ai didi

javascript - 按钮不触发 Ajax

转载 作者:行者123 更新时间:2023-12-03 05:45:40 29 4
gpt4 key购买 nike

我有一个通过 AJAX 向数据库提交元素的表单,我遇到的问题是,当我单击提交按钮时,它不执行任何操作,也不会调用 ajax 请求或任何其他操作。

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

最佳答案

在网址中使用“https://www.domain.com/test6/services/insert.php”此外,您使用的一些变量未定义,请修复它们,例如 payment_types 和持续时间。

关于javascript - 按钮不触发 Ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40338439/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com