Solved

AJAX to call a method

Posted on 2016-07-28
3
73 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 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 …

738 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