admin管理员组文章数量:1389231
Hello I want to ask you something how do I send a request to the webservice (restful) if the parameters which I will send more than one parameter?
edit:
this.sendRequest = function(){
var url="http://localhost:8081/inlinetrans/";
var client = new XMLHttpRequest();
var oriText ="";
var stemText ="";
var folText ="";
client.open("PUT", url, false);
client.setRequestHeader("Content-Type", "text/plain");
client.send(oriText,stemText,folText);
if (client.status == 200){
client.responseText;
}
else{
client.statusText;
}
}
client.send --> contents parameters which i want send to server
Hello I want to ask you something how do I send a request to the webservice (restful) if the parameters which I will send more than one parameter?
edit:
this.sendRequest = function(){
var url="http://localhost:8081/inlinetrans/";
var client = new XMLHttpRequest();
var oriText ="";
var stemText ="";
var folText ="";
client.open("PUT", url, false);
client.setRequestHeader("Content-Type", "text/plain");
client.send(oriText,stemText,folText);
if (client.status == 200){
client.responseText;
}
else{
client.statusText;
}
}
client.send --> contents parameters which i want send to server
Share Improve this question edited Jan 10, 2011 at 7:54 user495688 asked Jan 10, 2011 at 6:47 user495688user495688 9632 gold badges15 silver badges26 bronze badges 1- The same way you send requests normally, you just add more parameters. Please show us some more concrete code and a more concrete problem. – deceze ♦ Commented Jan 10, 2011 at 7:39
1 Answer
Reset to default 4If you are making a request for data, you should use a GET request. Any parameters required to fetch the correct data should be passed in the query string:
var url = 'http://localhost:8081/inlinetrans?key1=value1&key2=value2...';
client.open("GET", url, true);
client.send(null);
If on the other hand you want to send data to the server, you should use a POST request:
var data = ....
client.open("POST", url, true);
client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
client.setRequestHeader("Connection", "close");
client.send("data=" + encodeURIComponent(data));
Typically data
would be a JSON string. Of course, all of this depends on the API of the service. Without knowing these details, I cannot help beyond the typical example above.
本文标签: restjavascripthow to send request in restfulStack Overflow
版权声明:本文标题:rest - javascript : how to send request in restful - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744633985a2616711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论