我想发送一个带有文本区域内容的请求,但我只得到了一个数组,而不是所希望的字符串。
<textarea id="putup" name="textarea" cols="70" rows="15">http://www.example.com/?var=2EBR&n=1</textarea>
window.addEvent('domready', function() {
alert($('putup').value);
myRequest = new Request({
method: 'post',
url: 'build2.php',
}).post('var='+$('putup').value+'&uniquebutton='+$('uniquebutton').value);
});我的帖子是这样的:
Array ( [var] => http://www.example.com/?var=2EBR [n] => 1 [uniquebutton] => aqynnnisqopo )如何获取真正的字符串?
发布于 2013-03-25 00:06:46
你的代码很好,只是你试图在你的帖子中发送一个完整的网址而不对它进行编码-这可能会产生问题,如果url还包含参数-比如在你的例子中,&n=1是作为post参数发送的key=>n value=>1当你发送可能包含参数字符的url和字符串时,你需要使用encodeURIComponent,这样你保存这个网址的参数将包含整个网址,而不会打断它:
myRequest = new Request({
method: 'post',
url: 'build2.php',
}).post('var='+ window.encodeURIComponent($('putup').value)+'&uniquebutton='+$('uniquebutton').value);另一个小注释-在mootools中,你可以使用元素的get函数来获取任何元素的任何有效属性-所以你可以做$(‘but’).get(‘value’),但是经典的方法$('putup').value当然是非常好的。
https://stackoverflow.com/questions/15598934
复制相似问题