[英]How to send multiple data with ajax to PHP?
How to send multiple data as URL parameter to server side php script using only Javascript/Ajax. 如何仅使用Javascript / Ajax将多个数据作为URL参数发送到服务器端php脚本。
I don't need to use Jquer.y 我不需要使用Jquer.y
I am tying this way: 我这样绑:
xhttp.open("GET", 'spec_crawler.php?value='+postValue+'&tablename='+tablename+'&id='+postProdID+'\'', true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();
On server side I am getting only value: 在服务器端,我仅获得价值:
$html_snippet =$_GET['value'];
Others are empty. 其他人是空的。 but from client side I am sending the proper value.
但是我从客户端发送了正确的值。
Am I missing something fundamental? 我缺少基本的东西吗?
Content type " application/x-www-form-urlencoded " is usually used for POST requests. 内容类型“ application / x-www-form-urlencoded ”通常用于POST请求。
Encode each param value with encodeURIComponent
function: 使用
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/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.