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

  • Home
  • SEARCH
  • 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 6185083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:39:01+00:00 2026-05-24T01:39:01+00:00

I have just started into OO PHP and have created my first class. As

  • 0

I have just started into OO PHP and have created my first class. As it is, it works, but I want to tidy things up a bit.

Right now elements in the class call an ajax function that is declared in the head of the document.

I don’t want the class to be dependent on a proper head, so to keep it self contained, I moved the script functions into the class file. I could not find information on whether this is a no-no, so if it is, I want to know “Why is putting javascript/ajax in a PHP class bad form?” If, however, it is an acceptable practice, I have a trickier question.

The AJAX calls a PHP page who’s results will then fill in more of the class object on the page. But, I figure the class would be better if it didn’t rely on external php files either. So, I moved the files into functions on the class file. Here’s the tricky bit.

How do I get the AJAX to get the results from a function located on the same file as the AJAX call instead of an external page?

Here is my AJAX code so far. var url currently is the path to one of two possible PHP pages instead of the desired internal php functions. var dest is where in the class object the results end up.

function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
    ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();

function sndReq(url,dest) {
http.open('get',url);

http.onreadystatechange = function () {
    if (http.readyState == 4) {
        if (http.status == 200) {
            var responce = http.responseText;
            document.getElementById(dest).innerHTML = responce;
        }
    }
};

http.send(null);
}
  • 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-24T01:39:02+00:00Added an answer on May 24, 2026 at 1:39 am

    What you’re asking for sounds like xml-rpc or json-rcp. It lets you dynamically execute server-side code and get the results.

    Example javascript rpc library: http://barracudaserver.com/doc/WebServices/JRpcDoc.html

    However, I think that simply passing parameters is what you want. The simplest way is to pass get parameters in the url

    http://www.site.com/ajax.php?cmd=find_user&user_id=12
    

    then in php check for those parameters in the global $_GET variable

    if(isset($_GET["cmd"]) && $_GET["cmd"] == "find_user"){
       $user_id = $_GET["user_id"];
       //some server-side stuff    
       echo results;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started connecting android app with php My file works very fine
I have just started digging into JavaFX and have a requirement that I am
I just started getting into iPhone development. I have been mish-mashing tutorials and material
I've just started to use linq to sql and have run into a problem
I have just started PHP and mySQL and need to know if this is
I just recently started toying with output buffering and seem to have run into
I've just started diving into Node.js after several years of PHP programming and I
I have just started delving into the world of functional programming. A lot of
I just started looking into jQuery yesterday, before this I programmed in only PHP.
i literally just started looking into php, connecting to a remote database and returning

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.