Solved

AJAX to call a method

Posted on 2016-07-28
3
55 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 108

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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

930 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

13 Experts available now in Live!

Get 1:1 Help Now