【发布时间】:2020-10-06 08:52:22
【问题描述】:
如何为我的 XMLHttpRequest 编写 url,以便我可以将数据发送到我的控制器。
我现在拥有的是这样的:
var data = `post=${post}`;
var xhr = new XMLHttpRequest;
xhr.open("POST" , "<?= Router::url(array('controller'=>'posts','action'=>'add')) ?>", true);
xhr.setRequestHeader("Content-type" , "application/x-www-form-urlencoded");
xhr.send(data);
我知道我可以:
xhr.open("POST" , "/cakephp/posts/add/", true);
但我想要的是指定确切的控制器和操作,这样如果我更改我的网站名称,我就不会更改代码:
xhr.open("POST" , "/mywebsitename/posts/add/", true);
谢谢!
【问题讨论】:
-
为什么这对你不起作用?你从
<?=...得到什么URI -
我收到'localhost/cakephp/…'
标签: cakephp cakephp-2.x