繁体   English   中英

从具有开关的php函数中调用ajax($ this-> method)

[英]calling ajax from within a php function having a switch ($this->method)

当在具有这样的代码的php文件中创建XMLrequest时...我正在使用MVC(模型-视图-控制器结构),这是一个控制器php文件。

Controller_Institute extends Controller_Default{



function register(){
    try {

        $this->requireLogin();

        switch($this->method){
            case 'GET':
                $content = $this->render('institute_registration_confirm');
                break;
                case 'POST':

$result = mysql_query("SELECT * FROM password WHERE         pass='".mysql_real_escape_string($_POST['pass'])."'");
$num=mysql_num_rows($result);
if($num==2)
{
$content = $this->render('institute_registration');
}
else
{                   
                $content = $this-  >render("message",array('msg'=>'Your password is incorrect'));

}
break;
}                   
                $institute = R::dispense('institute');
                $institute- >import($_POST,'name,latitude,state,longitude,address,phone,year,url');
                $id = R::store($institute);

                }
                catch(exception $e){
        //If there was an error anywhere, go to the error page.
        $content = $this->render('error',array('exception'=>$e));   
    }
            $page = $this->render('default',array('content'=>$content));
            return $page;

}

我正在从函数内发送ajax请求 ...所以当ajax发送回请求时,它陷入了开关情况...然后响应文本成为函数返回值替换了实际文本...任何想法如何防止xml响应进入切换情况...? institute_registration是视图文件,我正在将该文件包含在我的框架中,然后从该文件中触发ajax函数以检查密码(启用注册表单)是否正确...

考虑到有限的信息和伪代码,我建议设置一个独立的页面,例如say ...“ ajax.php”,该页面是独立的,并且不会基于请求方法返回值。 使用AJAX的页面将需要从该页面进行POST或GET。

如果确定是否通过请求方法返回常规输出与AJAX输出,那么您将通过两种方式限制自己。 第一个是您将无法在网页上执行一项或两项(GET与POST),而不能同时执行两项。 另外,第二,涉及到AJAX,您将无法运行GET&POST AJAX请求,是的,您可以同时使用AJAX: http : //net.tutsplus.com/tutorials/javascript-ajax / 5方式使带有jquery的ajax调用/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM