【发布时间】:2016-06-16 09:00:42
【问题描述】:
我正在使用 Magento 进行开发。我需要对同一页面进行 ajax 调用以从相关的 php 函数中获取一些详细信息。当我在开发人员工具中检查时,在网络选项卡下,对当前页面进行了调用,但它显示以下错误:
Invalid URL: adminpteb/efund/efund.phtml
efund.phtml 是发起 ajax 调用的页面,要调用的 php 函数也位于同一页面内。 Magento 是否有自己的方式通过 ajax 获取 php 脚本?
参考此链接:Using Basic AJAX calls within Magento
我这样定义了 URl:url:/adminpteb/efund/efund.phtml,但仍然是同样的错误。
ajax 提醒'完成'并且正确的功能被拾取。但是函数 1 返回的值没有到达 ajax。 我的脚本:
$.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 脚本
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";
}
【问题讨论】: