Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 452721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:06:04+00:00 2026-05-12T22:06:04+00:00

I am moving from the PHP AJAX library xajax to jQuery AJAX. With xajax,

  • 0

I am moving from the PHP AJAX library xajax to jQuery AJAX.

With xajax, I could contain all my AJAX calls inside class methods by binding public class methods to javascript function names (eg. $this->registerFunction(‘javascriptFunctionName’, &$this, ‘classMethodName’)).

I am hoping there is a way I can do something similar with jQuery AJAX, whereby I can do something like this:

$('#myButton').click(function() {
    $.get('class|methodName',
    {
      parameter: value
    },
    function(data) {
      if (data) {
        ...
      }
      else {
        ...
      }
    });

    return false;
  });
});

I know you can AJAX calls to MVC controller methods, but unfortunately my legacy product doesn’t use MVC 🙁

Please tell me there is a way?

If not, is there a way to map a call to a global PHP function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:06:04+00:00Added an answer on May 12, 2026 at 10:06 pm

    To piggyback on what lane is saying you might want to make a really simple ajax controller and rout everything to it:

    <?php
    class AjaxController {
    
    protected $_vars = null;
    protected $ajax = null;
    
    
    public function __construct()
    {
      $this->_vars = array_merge($_GET, $_POST);
      $this->_ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&  $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
      $this->_response = null;
    }
    
    public function process()
    {
      if($this->isAjax()){
        if(isset($this->_vars['method']) && isset($this->_vars['class'])
        {
           $callback = array($this->_vars['class'], $this->_vars['method'];
        } elseif(isset($this->_vars['function'])){
          $callback = $this->_vars['function'];
        } 
    
        if(isset($callback) && is_callable($callback))
        {
           $this->_responseData = call_user_func($callback, $this->_vars);
           $this->sendResponse(200);
        } else {
           $this->_responseData = 'UH OH';
           $this->sendResponse(500);
        }
    
    
      }
    }
    
    public function sendResponse($httpStatCode = 200){
    
      // set headers and whatevs
      print $this->_response;
      exit;
    }
    
    } // END CLASS
    
    $contoller = new AjaxController();
    $controller->process();
    

    youd want to do some filtering on the params of ofcourse and probably make some nice rewriting in htaccess/vhost so you can use urls like /ajax/class/method?… But you get the general idea. You would probably want to have some kind of valid callbak registry to so youre not just calling any valid php callable… that could be dangerous 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm moving from the realm of just JS to php and Ajax. I've dabbled
I'm moving from a PHP background into Django development via python, mostly for the
We are moving from WebForms to MVC and and using a lot of jQuery.
I'm slowly moving from MSSQL to PostgreSQL. In MSSQL I could call editing of
I'm new to rails after moving from PHP and am having no end to
I'm moving from Globals and Singletons (=bad?) to Dependency Injections (=good?) in PHP and
I'm in the midst of moving a site from plain old php to the
I'm moving my PNS from php to Azure Mobile services. In PHP i had
I am moving some code from SimpleXML to PHP's DOM and don't quite get
I'm moving a PHP site from development to a production server and testing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.