如何使用jquery调用php控制器方法? [英] How to call a php controller method using jquery?

查看:373
本文介绍了如何使用jquery调用php控制器方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个web应用程序,我正在整合jquery在它...现在寻找ajax调用与jquery我的控制器函数....

I am developing a web application and i am integrating jquery in it... Now looking for ajax calls with jquery to my controller function....

jquery.ajax()将是有用的,我想这么...但如何调用我的控制器方法....

jquery.ajax() would be useful i think so... But how to call my controller method....

$.ajax({
        type: "POST",
        url: "http://localhost/codeigniter_cup_myth_new/index.php/libraryController/loadbookdetails",
        data: "",
        contentType: "application/json; charset=utf-8",
        async: false,
        dataType: "json",
        success: function(jsonObj) {

function loadbookdetails()
{
    //Paging 
        $college=$_SESSION['college'];
        $this->load->library('pagination');
        $data['bookdetails'] = $this->librarymodel->selectbook($college);
        //$data['rackOptionData'] = $this->librarymodel->selectrack();
         if(empty($data['bookdetails']))
          {
             $data['comment'] = 'no record found!';
          }

        $this->load->view('bookdetials',$data);
}

我在这里获取这个记录如何使用 jquery.ajax()函数和如何将 $ data 转换为json并与jquery一起使用, p>

I am fetching this records here how to use it with jquery.ajax() function and how to convert $data to json and use it with jquery and iterate with a table...

推荐答案

您无法直接将jQuery与PHP函数接口,因为它们不会同时运行:PHP在服务器端(通常生成HTML页面),jQuery是在客户端运行的。

You can't directly interface jQuery to PHP functions, because they don't run at the same time: PHP is executed on the server side (and usually generates the HTML page), jQuery is run on the client side.

您可以让jQuery对PHP页面的URL进行Ajax调用。该PHP页面将是所需的控制器,并执行请求的操作。

You would have jQuery make an Ajax call to a PHP page's URL. That PHP page would the desired controller, and perform the requested action(s).

是否有预定义的方式取决于您使用的PHP Framework(如果有)。

Whether there is a pre-defined way to do that depends on what PHP Framework you are using (if any).

这篇关于如何使用jquery调用php控制器方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆