【发布时间】:2015-01-26 22:40:49
【问题描述】:
我正在尝试在 Yii 框架中创建一个网上商店。现在我想在用户单击图标时取消设置会话。
我目前正在使用它向文件发送 json 调用,但我认为 json 调用中的 url 正在被我的 htaccess 重写。
JSON 调用:
$(document).ready(function(){
$('.glyphicon-trash').click(function(){
$.getJSON("ajax/load.php?action=unset&element="+$(this).parent(), function(data) {
alert(data.message);
});
});
});
我得到的错误:
GET http://mydomain.nl/my/path/to/site/ajax/load 404 (Not Found)
但它不是加载,它的 load.php!但是我的 htaccess 重写了那个 url..
.htaccess
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
在 Yii 中实现 ajax 调用的其他方式也不错,只是需要我多解释一下。
【问题讨论】:
-
当然
.htaccess会重写。CController::createUrl()有定义的路线怎么样?在教程中很容易找到。 -
嗨伙计,你为什么不这样传递 url:
ajax/load/action/unset/element=...? -
@Deer-Outdoor.nl 实际网址是什么?我需要您如何在浏览器中访问该网址?
-
@Deer-Outdoor.nl 哥们,还不清楚:(我的意思是你可以直接访问的url
标签: php ajax json .htaccess yii