$('input[name=id_num]').blur(function(){
$.ajax({
type: "POST",
url: "data_fetcher.php",
data: "idnum= ' + this.val + '",
success: function(html){
$("#results").append(html);
}
});
});
My data_fetcher.php looks like this:
我的data_fetcher。php是这样的:
<?php
$idnum = $_POST['idnum'];
.....
?>
1 个解决方案
#1
4
Since the function is an event (blur
) of the input, this
inside the function will reference to the DOM Object input
.
由于函数是输入的一个事件(模糊),所以函数内部的这个函数将引用DOM对象输入。
To access jQuery functions like val()
you need to transform it in a jQuery object. To do this, just enclose this
in a $()
accessor: $(this)
. This have the exact same result of $('input[name=id_num]')
, but is faster since jQuery don't need to make the search on the object list.
要访问像val()这样的jQuery函数,需要在jQuery对象中进行转换。为此,只需将其包含在$()访问器:$(this)中。这与$('input[name=id_num]')的结果完全相同,但更快,因为jQuery不需要在对象列表上进行搜索。
The data
line would then look like this:
数据线是这样的:
data: "idnum=" + $(this).val(),
Also take care with single quotes/double quotes. In your original code the result for data would be the string "idnum= ' + this.val + '
". Single quotes enclosed by double quotes are included in the string and have no effect in splitting code area from string area.
也要注意单引号/双引号。在原始代码中,数据的结果将是字符串“idnum= ' + this。val +’”。用双引号括起来的单引号包含在字符串中,在从字符串区域分割代码区域时没有作用。
#1
4
Since the function is an event (blur
) of the input, this
inside the function will reference to the DOM Object input
.
由于函数是输入的一个事件(模糊),所以函数内部的这个函数将引用DOM对象输入。
To access jQuery functions like val()
you need to transform it in a jQuery object. To do this, just enclose this
in a $()
accessor: $(this)
. This have the exact same result of $('input[name=id_num]')
, but is faster since jQuery don't need to make the search on the object list.
要访问像val()这样的jQuery函数,需要在jQuery对象中进行转换。为此,只需将其包含在$()访问器:$(this)中。这与$('input[name=id_num]')的结果完全相同,但更快,因为jQuery不需要在对象列表上进行搜索。
The data
line would then look like this:
数据线是这样的:
data: "idnum=" + $(this).val(),
Also take care with single quotes/double quotes. In your original code the result for data would be the string "idnum= ' + this.val + '
". Single quotes enclosed by double quotes are included in the string and have no effect in splitting code area from string area.
也要注意单引号/双引号。在原始代码中,数据的结果将是字符串“idnum= ' + this。val +’”。用双引号括起来的单引号包含在字符串中,在从字符串区域分割代码区域时没有作用。