未捕获的TypeError:无法将属性'value'设置为null [英] Uncaught TypeError: Cannot set property 'value' of null
本文介绍了未捕获的TypeError:无法将属性'value'设置为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用ajax请求将输入的文本传递给控制器.但是当我尝试执行JS文件时,我遇到了一个错误"Uncaught TypeError:无法将属性'value'设置为null".
I'm trying to pass the entered text to the controller using an ajax request. But i'm getting athe error "Uncaught TypeError: Cannot set property 'value' of null " when I tried to execute JS file..
这是HTMLcode:
Here is the HTMLcode:
<form action="">
<input type="text" class="searchbox1" name="search" placeholder="Search for Brand, Store or an Item..." value="text" />
<input type="button" class="searchbox_submit1" name="submit" value="text" onClick="javascript:getSearchText();">
</form>
这是JS代码:
function getSearchText() {
var searchText = document.getElementByName("search").value;
h_url=document.getElementById("u").value;
var theURL = h_url+'search_all/' + deptid + '/' + searchText + '/1';
$.ajax({
url : theURL,
fail: function(){
},
success : function() {
},
error:function(){
}
});
}
请帮助我解决此问题.
推荐答案
您没有ID为u
的元素.这就是发生错误的原因.
请注意,全局变量document.getElementById("u").value
表示您试图获取名称为u
且未在代码中定义的输入元素的值.
You don't have an element with the id u
.That's why the error occurs.
Note that the global variable document.getElementById("u").value
means you are trying to get the value of input element with name u
and its not defined in your code.
这篇关于未捕获的TypeError:无法将属性'value'设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文