【发布时间】:2019-05-28 03:24:17
【问题描述】:
向我的表中插入值我尝试了这个 GET xmlhttprequest 对象。 我在 URL 中的语法是否正确?它不工作。
document.getElementById('allsubmit').addEventListener('click',sendPost);
var com = document.getElementById('inputcompany').value;
var cat = document.getElementById('selectCategory').value;
var subcat = document.getElementById('selectsubCategory').value;
var descrip = document.getElementById('textdescription').value;
var exp = document.getElementById('datepicker').value;
function sendPost() {
var xhr = new XMLHttpRequest();
xhr.open('GET',"addingthevacancy.php?company='"+com+"'?category='"+cat+"'?subcategory='"+subcat+"'?description='"+descrip+"'?expdate='"+exp,true);
xhr.onprogress = function() {
//
}
xhr.onload = function() {
console.log("Processed..."+xhr.readystate);
console.log(this.responseText);
}
xhr.send();
}
我不知道这里出了什么问题。
【问题讨论】:
-
定义“它不起作用”:请参阅How to Ask 页面。
-
当你想传入多个 get 参数时,你需要像这样格式化它:
url?company=''&category='' -
URL 中的参数以
?开头,但每个参数应与下一个参数以&分隔,而不是?。 -
您还应该使用
encodeURIComponent()对参数进行正确编码,以防它们包含在URL中具有特殊含义的字符。 -
还建议您在进行更改时使用
POST而不是GET。GET应该只用于检索。
标签: javascript ajax http