dongre6404 2015-04-25 11:58
浏览 35

用Ajax调用PHP方法[重复]

This question already has an answer here:

I am trying to call another php file's function using ajax. Here is the Ajax Call :

function getBaseURL() {

         var pathArray = location.href.split( '/' );
         var protocol = pathArray[0];
         var host = pathArray[2];
         var url = protocol + '//' + host;
         return url+"/PhpProject2";
     }

   function getPageSaverUrl() {
return getBaseURL()+"/manager/content_manager/page_saver.php/SaveTest";
}

function savePage() {
 alert("Saving Page");
 var url = getPageSaverUrl();
 $.ajax({
   type: "POST",
   url: url,
   data: "name=hello",
   success: function(response){

     alert(response);
   }
 });
}

But i am not getting any response from the script. Can we call php funciton from ajax url parameter?

</div>
  • 写回答

2条回答 默认 最新

  • douchunji1885 2015-04-25 12:13
    关注

    You cannot call php function from ajax url parameter.

    You can use parameter with ajax call, see following code -

     function getPageSaverUrl() {
      return getBaseURL()+"/manager/content_manager/page_saver.php?param=SaveTest";
     }
    

    then in file page_saver.php, you need to fetch parameter 'param', which will have value 'SaveTest', then execute this function.

    Try this, let me know if you have any further query.

    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来