Wednesday, March 20, 2013

CakePHP and Ajax request

Hi

I am currently using ajax in multiple controllers in my application. I implemented the ajax functionality using the jQuery supported version.

$.ajax({
url:'getCountries',
type: "POST",
dataType: "html",
data:"data=" + result,
success: function(data){
                        //magic...
}
}
});

As you can see from the code above the url of this request is 'getCountries'. This means that if the request is made from 'http://localhost/appname/controllername/methodname' the request url will be  'http://localhost/appname/controllername/getCountries'. However if the url is different, say  'http://localhost/appname/controllername/methodname/7' (like in the edit view) or ( 'http://localhost/appname/controllername/methodname/order:Model.field' (like in the pagination) then the request url will dramaticly change to  'http://localhost/appname/controllername/methodname/getCountries' in the first case and even worse in the second. How can I avoid that?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: