如何使用XMLHttpRequest发送多个变量?

时间:2015-11-13 13:15:30

标签: ajax

我尝试将带有Ajax请求的两个变量发送到ajax.php

var xhReq               = new XMLHttpRequest();

xhReq.open              ( "GET", "ajax.php", false );
xhReq.setRequestHeader  ("Content-type", "application/x-www-form-urlencoded");
xhReq.send              ("cmd=ping&url=www.google.com");

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

你正在混合一些值。

GET请求:

xhReq.open( "GET", "ajax.php?cmd=ping&url=www.google.com", true );
xhReq.send();

POST请求:

xhReq.open( "POST", "ajax.php", true );
xhReq.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
xhReq.send( "cmd=ping&url=www.google.com" );
相关问题