使用AJAX / JSON在Yii框架框架、AJAX、JSON、Yii

由网友(冷月葬花魂)分享简介:林试图在Yii框架一个网上商店。现在我想,当用户点击一个图标,取消设置会话。Im trying to make a webshop in Yii framework. Now i want to unset a session when a user clicks on a icon.目前,我有它的工作就是发送一个...

林试图在Yii框架一个网上商店。现在我想,当用户点击一个图标,取消设置会话。

Im trying to make a webshop in Yii framework. Now i want to unset a session when a user clicks on a icon.

目前,我有它的工作就是发送一个JSON调用文件,但URL中的JSON呼叫正在rewrited我的htaccess的,我认为。

I currently have it working that is sends a json call to a file, but the url in the json call is being rewrited by my htaccess i think.

JSON电话:

$(document).ready(function(){
    $('.glyphicon-trash').click(function(){
        $.getJSON("ajax/load.php?action=unset&element="+$(this).parent(), function(data) {
            alert(data.message);
        });
    });
});

错误我得到:

Error i get:

GET http://mydomain.nl/my/path/to/site/ajax/load 404 (Not Found)

但它不加载,其load.php!但我的htaccess的重写该URL。

But it's not load, its load.php! But my htaccess rewrites that url..

的.htaccess

.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调用的其他方式也不错,只是我需要很多解释的话。

Other ways of implementing ajax calls in Yii are also good, only i need alot of explanation then.

推荐答案

好吧,我得到这个现在的工作,我做在现场查看的文件。现在,我把它称为这样的:

Okay i got this working now, i made a file under site view. Now i call it like:

$(document).ready(function(){
    $('.glyphicon-trash').click(function(){
        var session = 'session';
        $.getJSON("<?php echo Yii::app()->baseurl; ?>/load?action=unset&session="+session, function(data) {
            location.reload(true); //<---- this one does not work tho...
        });
        setInterval(function(){location.reload(true);}, 500);
    });
});
阅读全文

相关推荐

最新文章