weixin_33725239 2009-11-24 04:24 采纳率: 0%
浏览 23

用ajax调用类

I need some help with this please I can't get a handle on it.

The problem is that I want to call a class method, in this case with static methods with an ajax call.

I have put the helper class in the same folder as the script that is called by ajax for easy referencing and try to include it. Could it be that my refencing is wrong?

If I make a testclass in the file that is called by ajax I can get a response.

class test {
    public function testit() {
        return "testit";
    }
}
$t=new test;
$check= $t->testit();



switch($action) {
case "someaction":
    $data = array();
    $file='input_helper.php';
    include_once $file;

    $check= input_helper::ip_address();
    header('Content-type: application/json');

    $output = array(
        "check" => $check,
        "user" => $data
        );

    echo json_encode($output);

    exit(0); // Stop script.

    break;
//...

EDIT FOR MORE CLARIFICATION

The action is set as a post variable in the ajax function The ajax url points to a script that takes some action based on the posted variables

thanks, Richard

  • 写回答

1条回答 默认 最新

  • Lotus@ 2009-11-24 05:01
    关注
    <?php
      include_once 'your/class/path/helper_class.php';
      .
      .
    

    at the top of your PHP page should do it. it really has nothing to do with AJAX. If your PHP file is in fact being hit on the callback, then that should work properly.

    Optionally, to test that your path is correct, if you do:

     <?php 
         require 'your/class/path/helper_class.php';
         .
         .
    

    If the path is not correct PHP will throw a fatal E_ERROR level error.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)