我如何将输入文本框值的参数传递给jQuery中的Ajax [英] How do i pass parameters that is input textbox value to ajax in jQuery
本文介绍了我如何将输入文本框值的参数传递给jQuery中的Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Ajax代码
$(document).ready(function() {
$("#sub").click(function() {
$.ajax({
type: "POST",
url: "jqueryphp.php",
data: "txt1=" + txt1,
success: function(result) {
$("div").html(result);
}
});
});
});
这是表单代码.我想将txt1值传递给Ajax
This is the form code . I want to pass txt1 value to Ajax
<input type="text" name="txt1" id="txt1" /><br>
<input type="button" name="sub" id="sub" value="click Me" />
我想使用此Ajax函数将 txt1 值传递给我的php页面.
I want to pass txt1 value to my php page using this Ajax function.
请告诉我Ajax的data属性到底会出现什么
Please tell me what exactly will come in the data attribute of Ajax
推荐答案
将数据作为对象而不是字符串发送,并获取文本字段的值,请使用val():
Send data as an object instead of a string and to retreive the value of the text field, use val():
$(document).ready(function() {
$("#sub").click(function() {
$.ajax({
type: "POST",
url: "jqueryphp.php",
data: {
txt1: $("#txt1").val()
},
success: function(result) {
$("div").html(result);
}
});
});
});
这篇关于我如何将输入文本框值的参数传递给jQuery中的Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文