[英]How to send multiple data with ajax to PHP?
如何仅使用Javascript / Ajax将多个数据作为URL参数发送到服务器端php脚本。
我不需要使用Jquer.y
我这样绑:
xhttp.open("GET", 'spec_crawler.php?value='+postValue+'&tablename='+tablename+'&id='+postProdID+'\'', true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();
在服务器端,我仅获得价值:
$html_snippet =$_GET['value'];
其他人是空的。 但是我从客户端发送了正确的值。
我缺少基本的东西吗?
内容类型“ application / x-www-form-urlencoded ”通常用于POST请求。
使用encodeURIComponent
函数对每个参数值进行编码:
var params = 'value=' + encodeURIComponent(postValue) +'&tablename=' + encodeURIComponent(tablename) +'&id='+ encodeURIComponent(postProdID);
xhttp.open("GET", 'spec_crawler.php?' + params, true);
xhttp.send();
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.