![](/img/trans.png)
[英]How to pass the value from input checkbox to URL Parameters in jquery
[英]How do i pass parameters that is input textbox value to ajax in jQuery
我的Ajax代碼
$(document).ready(function() {
$("#sub").click(function() {
$.ajax({
type: "POST",
url: "jqueryphp.php",
data: "txt1=" + txt1,
success: function(result) {
$("div").html(result);
}
});
});
});
這是表單代碼。 我想將txt1值傳遞給Ajax
<input type="text" name="txt1" id="txt1" /><br>
<input type="button" name="sub" id="sub" value="click Me" />
我想使用此Ajax函數將txt1值傳遞給我的php頁面。
請告訴我Ajax的data屬性到底會出現什么
將數據作為對象而不是字符串發送,並獲取文本字段的值,請使用val():
$(document).ready(function() {
$("#sub").click(function() {
$.ajax({
type: "POST",
url: "jqueryphp.php",
data: {
txt1: $("#txt1").val()
},
success: function(result) {
$("div").html(result);
}
});
});
});
你的意思是:
$(document).ready(function() {
$("#sub").click(function() {
var txt1 = $("#txt1").val(); //textbox value
$.ajax({
type: "POST",
url: "jqueryphp.php",
cache: false,
data: "txt1=" + txt1,
dataType: "html",
success: function(result) {
$("div").html(result);
}
});
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.