Solved

AJAX to call a method

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

12 Experts available now in Live!

Get 1:1 Help Now