Uncaught TypeError: Cannot read property 'value' of null

来源:互联网 发布:软件系统架构设计 编辑:程序博客网 时间:2024/04/28 11:42
Uncaught TypeError: Cannot readproperty 'value' of null

一个js方法调用另一个js方法,另一个js方法调用不到页面节点值

由于前一个js方法访问action链接跳转,页面获取不到id参数值

解决办法:第二个方法调用第一个方法的值

$(document).ready(function() {var id=document.getElementById("courseid").value;$.ajax({type : 'post',url : 'http://localhost:8888/AMOOC/video_showDetail.action',contentType : 'application/x-www-form-urlencoded; charset=UTF-8',data : {id : id},success : function(data) {getPicture(id);},error : function erryFunction() {$("#div_course").html("error");}});});
function getPicture(id){$.ajax({type : 'post',url : 'http://localhost:8888/AMOOC/course_isFocused.action',contentType : 'application/x-www-form-urlencoded; charset=UTF-8',data : {id : id},success : function(data) {alert(data);},error : function erryFunction() {$("#div_course").html("error");}})};

如果直接在第二个方法中取id值会报错

function getPicture(){var id=document.getElementById("courseid").value;$.ajax({type : 'post',url : 'http://localhost:8888/AMOOC/course_isFocused.action',contentType : 'application/x-www-form-urlencoded; charset=UTF-8',data : {id : id},success : function(data) {alert(data);},error : function erryFunction() {}})};







</pre><pre>
                                             
0 0
原创粉丝点击