George_Fal 2011-04-11 06:53 采纳率: 0%
浏览 24

AJAX使用php类

I am starting to learn about classes in php and was wondering how I would be able to call a function that is within a class, but using it in the url field for ajax.

Basically, I have:

$(document).ready(function(){
    $('#submit').click(function(e) {
        $.ajax({
            type : 'POST',
            url : 'addCustomer.php',
            dataType : 'json',
            data:{
                lastName : $('#add_LN').val(),
                firstName : $('#add_FN').val(),
                phone : $('#add_PN').val(),
                dob : $('#add_DOB').val()
            },

What my addCustomer.php does is create an instance of my class "customer_module" and then calls functions within customer_module.

But I would like to get rid of addCustomer.php all together, and just call the function in customer_module.php. This functions name will be addCustomer($last_name, $first_name, $phone, $dob).

customer_module.php

    class customer_module
    {

        public function addCustomer($last_name, $first_name, $phone, $dob)
        {
...
        }

     }

What should I change my ajax function to look like?

  • 写回答

2条回答 默认 最新

  • 程序go 2011-04-11 06:58
    关注

    You can't do this, you always need a wrapper around it. There are PHP Frameworks like Kohana (derived from CodeIgniter), which do this kind of mapping URLs to functions and classes but this is very difficult and in your case it would be better to keep on using the addCustomer.php solution.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器