My controller has this function in it:
public function saveLeadDaysAction(){
echo "works";
}
And in the phtml template I try:
jq("#prodcal_leaddays").on("blur", function(e){
$saveurl="<?=$this->getUrl('prodcal/adminhtml_prodcaltab/saveLeadDays');?>";
console.log('$saveurl');
jq.post($saveurl,{'id':'test'},function(d){
console.log(d);
});
});
The URL seems to return the entire page of the admin control panel, not the expected text works. However, if I open the URL directly in the browser, it displays the expected text.
What am I doing wrong?
Oh, and I tried adding ?isAjax=trueat the end of the url that returns:
{"error":true,"message":"Invalid Form Key. Please refresh the page."}
EDIT: Just clarify: -
getUrlGenerates a URL, for example http://localhost/devmagento/index.php/prodcal/adminhtml_prodcaltab/saveLeadDays/key/d3c92257c664d8d207f5a0bdeb3edebf/in the console. If I copy this URL from the console and paste it into the browser, it works as expected, and I get the text works. But when used with a jQuery post, it crashes and redirects to the control panel.
2: , post, , , GET, getUrl, , , ajax, javascript.
, :
jq("#prodcal_leaddays").on("blur", function(e){
$saveurl="<?=$this->getUrl('prodcal/adminhtml_prodcaltab/saveLeadDays',array('id'=>'test'));?>";
console.log($saveurl);
jq.get($saveurl,function(d){
console.log(d);
});
});