如何使用此Ajax函数发布多个输出? [英] How do I POST multiple outputs with this ajax functions?
本文介绍了如何使用此Ajax函数发布多个输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用ajax发送一个输出即json的'OPTIONS'的函数.现在我需要发布多个说两个输出.如何修改此函数,以便可以发布两个值. 这是我的ajax函数.
I have a function that send one output i.e. 'OPTIONS' as json using ajax. Now I need to POST multiple say two outputs. How do I modify this function so that I could POST two valiues. Here is my ajax function.
function ADDLISITEM(form)
{
var options = form.txtInput.value;
options = JSON.stringify(options);
var url = "send_mysql.php"
var request = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
request=new XMLHttpRequest();
}
else
{// code for IE6, IE5
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRequestHeader("Connection", "close");
request.onreadystatechange = function(){
if (request.readyState == 4) {
if (request.status == 200) {
//alert('POST');
} else {
alert(request.status); // fails here
}
}
}
request.send("options=" + encodeURIComponent(options).replace(/%20/g, '+'));
}
</script>
推荐答案
向request.send
调用中添加另一个参数,如下所示:
Add another parameter to the request.send
call like this:
var someOtherValue = JSON.stringify({actual : "data", goes : "here"});
request.send("options=" + encodeURIComponent(options).replace(/%20/g, '+') + "&someOtherValue=" + encodeURIComponent(someOtherValue).replace(/%20/g, '+'));
这篇关于如何使用此Ajax函数发布多个输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文