Solved

AJAX to call a method

Posted on 2016-07-28
3
67 Views
Last Modified: 2016-08-03
Can you use AJAX to call a Method inside of a class? If so, is there a link to a really good yet simple example?
0
Comment
Question by:rgranlund
3 Comments
 
LVL 9

Assisted Solution

by:Moussa Mokhtari
Moussa Mokhtari earned 250 total points
ID: 41733952
@rgranlund
You can't call a method inside a class ,the only thing you can do is to call a php page
but you can call a php page that will call that method for you
ex :
function test() {
    var request = new XMLHttpRequest();
    request.open('GET', 'myfile.php', false);
    request.send();
    if (request.status === 200) {
      alert(request.responseText);
    }
}

Open in new window

myfile.php

<?php
include_once('myclass.php');
$obj = new myclass();
$obj->mymethod();
echo $obj
?>

Open in new window

1
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 41733963
The short answer is "yes, you can call a method."  But the longer and more articulate answer would be closer to what Moussa says.  You have to "call" a URL, which means to make an HTTP request.  The HTTP request can send parameters to the URL that you request.  These parameters can include the name of the class, the method, the arguments you want to send to the method, and any other information that is needed to complete the HTTP request.

Maybe if you can give us the details of why you want to do this, we can help with a sample implementation.  Is there any code you have tried yet?

Some background material is available in these articles:
0
 
LVL 34

Expert Comment

by:Slick812
ID: 41735842
greetings rgranlund, , You ask this question -
    "Can you use AJAX to call a Method inside of a class?"

I really can NOT understand what you may mean in your Question? ? ? ? ? ? ?

Can you please tell us about what you need to do for the web page DISPLAY result you want to have seen by the page user, , what data (as a database SELECT), , or what inputs in a page FORM do you have, and what is the Goal you need to end up with on the display page.
What operations do you think the AJAX http exchange needs to accomplish to get to your Goal?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question