dongniechi7825 2011-03-30 15:43
浏览 26
已采纳

jquery和.ajax的问题​​ - 空白响应

This is my setup.

I have a html registration form, when a user has typed in an username, email etc. The information is sent like this:

var processFile = "../inc/ajax.inc.php"; 

$("#register").change(function(){

    var postdata =  $("#register").serialize(); 

    $.ajax({
        type: "POST", 
        url: processFile, 
        data: "action=reg_validation&" + postdata , 
        success: function(data){                        
        }

    }); 

    console.log("action=reg_validation&" + postdata);   

}); 

This prints for example:

action=reg_validation&u=user&p=123&p2=&e=&r=

My ajax.inc.php file:

/*
 * Create a lookup array for form actions
 */
$actions = array(
        'reg_validation' => array(
                'object' => 'Intro',
                'method' => 'check_reg_form' 
        )
    );

if ( isset($actions[$_POST['action']]) )
{
    $use_array = $actions[$_POST['action']];   
    $obj = new $use_array['object'];

    echo $obj->$use_array['method'];      
}

function __autoload($class_name)
{
    $filename = '../../sys/class/class.'
        . strtolower($class_name) . '.inc.php';
    if ( file_exists($filename) )
    {
        include_once $filename;
    }
}

This code is supposed to call a class called Intro and a function called check_reg_form in class.intro.inc.php. This works almost.

If I start my class.intro.inc.php with:

echo "test 1"; 
exit(); 

I get test 1 in response, but this does not work:

class Intro
{
    public function check_reg_form()
    {
           echo "test 2"; 
    }
}

Not sure why this doesn't work... I get a blank response when I should get test 2..

  • 写回答

1条回答 默认 最新

  • dongtang4019 2011-03-30 16:05
    关注

    I think you're just missing parens.

    $obj = new $use_array['object']();      
    echo $obj->$use_array['method']();   
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试