是不是可以使用JavaScript读取AJAX加载的HTML元素?

时间:2012-03-13 17:59:42

标签: javascript ajax

我需要使用AJAX获取一个填充了数据库选项的选择框,并将其插入到FORM中。接下来我需要阅读选择框的值,以便使用document.getElementById('box1')的JavaScript进行进一步处理,但我收到错误:TypeError: Cannot read property 'value' of null 以下是有关情况的一些细节:

我在一个选项中有多种服务类型,每种服务类型都有一个单独的表。选择服务时,将调用以下函数:

function get_services(type){
  var url = "services/fetch/all/"+ type.toLowerCase();  
  get_data(url); 
  // This above functions loads the Selectbox named box1 using AJAX and embeds it inside the form at a predefined place
}

现在这是我点击按钮时调用的功能:

function get_cost(){
  var service = document.getElementById('service').value;
  var service_id = document.getElementById("box1").value; 
  // this above line shows the error
  alert(service + " , " + service_id);
}

是否无法引用使用JavaScript加载的HTML元素?

0 个答案:

没有答案