Page 1 of 1

[SOLVED] Ajax call redirect to login page...

Posted: Fri Jul 08, 2011 1:36 am
by cve
Hi everyone, I creating module like shop, and I want to make hierarchy manager for categories, with drag & drop. I have to save changes in that categories throught ajax, and when I try send POST data with jquery ajax, cms made simple give me login page... my files structure is very simple. I have action.defaultadmin.php witht this content:

Code: Select all

<?php
$this->smarty->assign('urlajax', $this->CreateLink($id, 'save_order_categories_tree', $retrunid, '', array('disable_theme' => true, 'showtemplate' => false ), '', true));
$this->smarty->assign('tree', $this->_RenderTree($this->_getTree()));
echo $this->ProcessTemplate('categories.tpl');
in my smarty variable called 'urlajax' i have:

Code: Select all

'http://localhost/cms/admin/moduleinterface.php?mact=Sklep,m1_,save_order_categories_tree,0&sp_=5d2fce4f&m1_disable_theme=true&m1_showtemplate=false'
and my template code categories.tpl rendered by defaultadmin

Code: Select all

<__script__ type="text/javascript">
    var ajax_url = '{$urlajax}';
    {literal}
    $(document).ready(function(){

        $('ul.sortable').nestedSortable({	
            disableNesting: 'no-nest',
            forcePlaceholderSize: true,
            handle: 'div',
            items: 'li',
            opacity: .6,
            placeholder: 'placeholder',
            tabSize: 10,
            tolerance: 'pointer',
            toleranceElement: '> div'
        });

     
        $("#save").click(function(){
            var tree = $('ul.sortable').nestedSortable('toArray', {startDepthCount: 0});;
            var ajax_res = false;
            $.ajax({
                type: 'POST',
                url:  ajax_url,
                data: {data: tree},
                cache: false,
                async: false,
                success: function(res) {
                    ajax_res = true;
                    console.log(res);
                    alert(res);
                }
            });
            //console.log(ajax_res);
            return ajax_res;
        });//end save
        $('#toArray').click(function(e){
            arraied = $('ul.sortable').nestedSortable('toArray', {startDepthCount: 0});
            console.log(arraied);
        }) 

    });//end ready
    {/literal}
</__script>
{$tree}
<button id="save">save</button>
When I click save button, and watching how ajax request is processing by firebug, it shows: http://localhost/cms/admin/login.php
What is going wrong... ? please help... :(

UPDATE:
I've just solved it... Why, the method of CMS Made Simple for generating link (CreateLink) add's the "amp;" word??? to the final link???, ajax call work's only if the link is looks like that:

Code: Select all

http://localhost/cms/admin/moduleinterface.php?mact=Sklep,m1_,save_order_categories_tree,0&sp_=aa8730e6
and not like that (with "amp;" after "&" sign):

Code: Select all

http://localhost/cms/admin/moduleinterface.php?mact=Sklep,m1_,save_order_categories_tree,0&sp_=aa8730e6
the code which solve this problem is:

Code: Select all

$link = 'http://localhost/cms/admin/moduleinterface.php?mact=Sklep,m1_,save_order_categories_tree,0&sp_=aa8730e6';
$good_link = str_replace('amp;', '', $link);
Why I have to do it manually???

Re: [SOLVED] Ajax call redirect to login page...

Posted: Mon Aug 01, 2011 12:48 pm
by scooper
Can't say why CreateLink returns encoded links but it might be better to use smarty to decode your url in the template rather than using str_replace which could remove things you don't want it to.

So in your template you could use

Code: Select all

    var ajax_url = '{$urlajax|html_entity_decode}';
instead of

Code: Select all

    var ajax_url = '{$urlajax}';