vanamerongen
vanamerongen

Reputation: 837

Path in an AJAX call keeps changing in ZF2

I have a bit of an annoying problem in Zend Framework 2. My js, which is located in my public/js folder, calls an action in the controller for my admin module. This is the call:

$.post('admin/expand', {
        id: CCID
    },function(data){
        if(data.hasOwnProperty('info')){   
            expand(data.info);
        } else {
            console.log('Can\'t find customer info.');
        }
    },'json'); 

The call works fine normally, but then sometimes it won't be able to find the action. The console will say:

POST http://localhost/admin/admin/expand 404 (Not Found) 

So I'll change the path in the AJAX to just 'expand' instead of 'admin/expand' and it'll work for a while... and then it won't until I change it back!

So it seems that sometimes it gets confused about the routing and sometimes it doesn't. Is this a namespace problem? The js file is supposed to be in my root/public/js, right? Does anyone know what the problem is here?

Upvotes: 0

Views: 223

Answers (1)

pjabang
pjabang

Reputation: 199

Try changing the url from admin/expand to /admin/expand . It is more pragmatic to use ZF2 routes.

Upvotes: 1

Related Questions