Solved

AJAX to call a method

Posted on 2016-07-28
3
48 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
Comment Utility
@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 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
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 33

Expert Comment

by:Slick812
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now