admin管理员组文章数量:1023773
I want to submit a POST request while passing a url among other parameters. I have the following script but it is not working.
var params = "param1="+param1_value+"&url="+url_value;
var xhr = new XMLHttpRequest();
xhr.open("POST", action_url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
console.log("Done");
}
}
xhr.send(params);
Assuming that the url_value
is something like this:
=&email=domain%40email%2E&blah=1234
what would be wrong with this script?
I want to submit a POST request while passing a url among other parameters. I have the following script but it is not working.
var params = "param1="+param1_value+"&url="+url_value;
var xhr = new XMLHttpRequest();
xhr.open("POST", action_url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
console.log("Done");
}
}
xhr.send(params);
Assuming that the url_value
is something like this:
https://www.domain./blah?param=&email=domain%40email%2E&blah=1234
what would be wrong with this script?
Share Improve this question asked Aug 18, 2015 at 7:23 Giannis TzagarakisGiannis Tzagarakis 5306 silver badges29 bronze badges 1- stackoverflow./questions/1714786/… – Ciro Santilli OurBigBook. Commented May 15, 2016 at 9:07
3 Answers
Reset to default 2Take a look at this question/answer - Should I URL-encode POST data?
Your sample value for url_value
is using the HTML Entity Code. Because of the &
symbol in the value, it is being sent as multiple values. You probably need to URL encode it so it looks like this
https%3A%2F%2Fwww.domain.%2Fblah%3Fparam%3D%26email%3Ddomain%40email.%26blah%3D1234
You may have a problem when trying to access another domain/website. The receiving side must have the Access-Control-Allow-Origin
header in its return message.
You can probably find your solution in this answer.
You are missing quotation to the url string value,alert the parameter string as below
var params = "param1='"+param1_value+"'&url='"+url_value+"'";
I want to submit a POST request while passing a url among other parameters. I have the following script but it is not working.
var params = "param1="+param1_value+"&url="+url_value;
var xhr = new XMLHttpRequest();
xhr.open("POST", action_url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
console.log("Done");
}
}
xhr.send(params);
Assuming that the url_value
is something like this:
=&email=domain%40email%2E&blah=1234
what would be wrong with this script?
I want to submit a POST request while passing a url among other parameters. I have the following script but it is not working.
var params = "param1="+param1_value+"&url="+url_value;
var xhr = new XMLHttpRequest();
xhr.open("POST", action_url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
console.log("Done");
}
}
xhr.send(params);
Assuming that the url_value
is something like this:
https://www.domain./blah?param=&email=domain%40email%2E&blah=1234
what would be wrong with this script?
Share Improve this question asked Aug 18, 2015 at 7:23 Giannis TzagarakisGiannis Tzagarakis 5306 silver badges29 bronze badges 1- stackoverflow./questions/1714786/… – Ciro Santilli OurBigBook. Commented May 15, 2016 at 9:07
3 Answers
Reset to default 2Take a look at this question/answer - Should I URL-encode POST data?
Your sample value for url_value
is using the HTML Entity Code. Because of the &
symbol in the value, it is being sent as multiple values. You probably need to URL encode it so it looks like this
https%3A%2F%2Fwww.domain.%2Fblah%3Fparam%3D%26email%3Ddomain%40email.%26blah%3D1234
You may have a problem when trying to access another domain/website. The receiving side must have the Access-Control-Allow-Origin
header in its return message.
You can probably find your solution in this answer.
You are missing quotation to the url string value,alert the parameter string as below
var params = "param1='"+param1_value+"'&url='"+url_value+"'";
本文标签: javascriptXMLHttpRequest POST parameter encodingStack Overflow
版权声明:本文标题:javascript - XMLHttpRequest POST parameter encoding - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745602791a2158556.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论