I'm using Magento for my development. I need to make ajax call to the same page to fetch some detail from related php function. As I checked in the developer tool, under network tab, the call is made to the current page but it displays the following error:
Invalid URL: adminpteb/efund/efund.phtml
efund.phtm
l is the page I'm where the ajax call is initiated and the php function to be invoked also resides within the same page. Is the Magento has own way of fetching php scripts via ajax?
Referred to this link: Using Basic AJAX calls within Magento
And I defined the URl like this: url: /adminpteb/efund/efund.phtml
, but still same error.
the ajax alerts 'complete' and correct function is picked up. However the value returned by function 1 is not reaching the ajax. My script:
$.ajax({
method: "GET",
url: "efund.phtml",
data: { function_to_call: 0, id: cl[3] }
}).fail(function() {
alert( "error" );
}).always(function() {
alert( "complete" );
}).done(function( msg ) {
var obj = jQuery.parseJSON( msg );
alert( "ID obtained from server is " + obj.id );
});
PHP script
switch ($_GET['function_to_call'])
{
case 0:
{
function1($_GET['id']);
break;
}
case 1:
{
function2();
break;
}
default: break;
}
function function1() {
echo "ID= ".$_GET['id'];
return json_encode(array ( "id" => $param ) );
}
function function2() {
echo "This is function 2";
}