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 5995003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:53:56+00:00 2026-05-22T23:53:56+00:00

I’ve been using Codeigniter for the past two years and really have become a

  • 0

I’ve been using Codeigniter for the past two years and really have become a big fan, but over the past year I’ve found myself writing more and more javascript than PHP.

In the begining, I would write everything with PHP, but now I find myself using $.ajax all the time. And I sort of feel like Im repeating myself between javascript and php.

I know that CI does give you some good control over ajax, but Im still having two write a ton of javascript and I’d like to consolidate if at all possible.

I guess what I am looking for is a php framework that integrates tightly with jQuery’s $.ajax.

  • 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-22T23:53:56+00:00Added an answer on May 22, 2026 at 11:53 pm

    I use this piece of code in Javascript. Backend wise things are organized in a MVC type of organisation, so things affecting one module are usually grouped together. In general I also create a sperate module for a seperate model, but in some cases you may deviate from this principle.

    My setup is with symfony at the back and plain jquery at the front. There are some approaches that automatize this part, like http://javascriptmvc.com/, I find it too restricting in many parts. Here is my workflow for integrating php and jquery.

    PHP

    Execute a piece of code and wrap it inside a try/catch block. This way error messages may be propagated to the frontend. This method helps in that regard to convert exceptions to a readable error. (to debug from json).

    try {
        //... execute code ..  go about your buisness..
        $this->result = "Moved  " . count($files) . " files ";
        // result can be anything that can be serialized by json_encode()
    } catch (Exception $e) {
       $this->error = $e->getMessage() . ' l: '  . $e->getLine() . ' f:' . $e->getFile();
       // return an error message if there is an exception. Also throw exceptions yourself to make your life easier.
    }
    // json response basically does something like echo json_encode(array("error" => $this->error, "result" => $this->result))
    return $this->jsonResponse();
    

    For error handling I often use this to parse errors.

    public function parseException($e) {
        $result = 'Exception: "';
        $result .= $e->getMessage();
        $trace = $e->getTrace();
        foreach (range(0, 10) as $i) {
            $result .= '" @ ';
            if (!isset($trace[$i])) {
                break;
            }
            if (isset($trace[$i]['class'])) {
                $result .= $trace[$i]['class'];
                $result .= '->';
            }
            $result .= $trace[$i]['function'];
            $result .= '(); ';
            $result .= $e->getFile() . ':' . $e->getLine() . "\n\n";
        }
    
        return $result;
    }
    

    Javascript side

    /**
     * doRequest in an ajax development tool to quickly execute data posts.
     * @requires jQuery.log
     * @param action (string): url for the action to be called. in config.action the prefix for the url can be set
     * @param data (object): data to be send. eg. {'id':5, 'attr':'value'}
     * @param successCallback (function): callback function to be executed when response is success
     * @param errorCallback (function): callback function to be executed when response is success
     */
    jQuery.doRequest = function (action, data, successCallback, errorCallback) {
        if (typeof(successCallback) == "undefined") {
            successCallback = function(){};
        } 
        if (typeof(errorCallback) == "undefined") {
            errorCallback = function(data ){
                alert(data.error);
            };
        }
        jQuery.log(action);
    
        jQuery.post(action, data, function (data, status)
        {
    
            jQuery.log(data);
            jQuery.log(status);
            if (data.error !== null || status != 'success') {
                // error handler
                errorCallback(data);
            } else {
                successCallback(data);
            }
        },'json');
    };
    

    Note: the error callbacks are very nice if you combine them with something like pNotify

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build

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.