我在这样的函数中初始化了一个变量matching_id:
if (validation()) {
matching_rule(sensor, nameE, cond, newVal);
firing_rule(firingType, matching_id, nameE);
console.log(matching_id);
document.getElementById("form1").submit(); //form submission
alert("Matching_id: "+matching_id[0]+"\nSensor: "+sensor +"\nConditions: "+cond + " \nDevice: "+ dev +"\nNew val: "+newVal+"\n Selected: "+ firingType + "\n Name : " + nameE + " \n Email : " + email + " \n Form Id : " + formID + "\n\n Form Submitted Successfully......");
}
当我在这里尝试访问matching_id时:
function matching_rule(type,name,cond,val){
var req = '{"dataPredicate":{"'+cond+'": [ {"var": "value.'+type+'"},'+val+'] },"enabled": true,"name": "'+name+'"}';
req_match.open('POST', url_matching, true);
req_match.setRequestHeader('Accept', 'application/json');
req_match.setRequestHeader('Content-type', 'application/json');
req_match.setRequestHeader('X-API-KEY', kAPI);
req_match.onreadystatechange = function(){
console.log(req_match.status);
if (req_match.status >= 200 && req_match.status < 400) {
console.log(req_match);
request_m.onload = req_m; // it's called here
request_m.open('GET', url_matching, true);
request_m.setRequestHeader('Accept', 'application/json')
request_m.setRequestHeader('Content-type', 'application/json')
request_m.setRequestHeader('X-API-KEY', kAPI)
request_m.send();
}else {
console.log("NOOOOOO MATCHING RULE");
}
}
console.log(req);
req_match.send(req);
}
注意:match_rule函数调用req_m函数。 我得到了未定义。我无法获取其价值。
编辑: 这是调用req_m函数的matching_rule函数。
.container