Ive been having great frustration for hours now trying to remember my AJAX!
我现在一直在努力记住我的AJAX,感到非常沮丧!
Im trying to write a function which will be called that will simply POST 4 variables to a given URL, written in javascript and not jquery such as:
我试图编写一个将被调用的函数,只需将4个变量POST到给定的URL,用javascript编写而不是jquery,例如:
function postVariables(URL, var1, var2, var3, var4)
{
......
return true;
}
Can anyone help?
有人可以帮忙吗?
1 个解决方案
#1
0
Been a while since I've done this without jQuery but something like
已经有一段时间了,因为我没有jQuery这样做,但有点像
function postVariables(URL, var1, var2, var3, var4)
{
var xhr= new XMLHttpRequest();
var postvars = "var1=" + var1 + "&var2=" + var2 etc;
xhr.open("POST", URL, true);
xhr.setRequestHeader("Content-type", "text/html;");
xhr.setRequestHeader("Content-length", postvars.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(postvars);
}
I'm sure my syntax is off somewhere or other, but you should be able to search for XmlHttpRequest and find some valid samples.
我确定我的语法在某处或其他地方,但你应该能够搜索XmlHttpRequest并找到一些有效的样本。
ref: http://www.w3.org/TR/XMLHttpRequest/
参考:http://www.w3.org/TR/XMLHttpRequest/
#1
0
Been a while since I've done this without jQuery but something like
已经有一段时间了,因为我没有jQuery这样做,但有点像
function postVariables(URL, var1, var2, var3, var4)
{
var xhr= new XMLHttpRequest();
var postvars = "var1=" + var1 + "&var2=" + var2 etc;
xhr.open("POST", URL, true);
xhr.setRequestHeader("Content-type", "text/html;");
xhr.setRequestHeader("Content-length", postvars.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(postvars);
}
I'm sure my syntax is off somewhere or other, but you should be able to search for XmlHttpRequest and find some valid samples.
我确定我的语法在某处或其他地方,但你应该能够搜索XmlHttpRequest并找到一些有效的样本。
ref: http://www.w3.org/TR/XMLHttpRequest/
参考:http://www.w3.org/TR/XMLHttpRequest/