1

I need to call a PHP Script and Run (a function) on the Server .. by calling from client side by using Javascript. I know only Ajax Call from Javascript.

  • Is there any other standardized way to communicate from Javascript to PHP?
  • Please correct me if i'm wroing. Is XMLRPC an another approach?
2
  • 1
    No. But you can redirect the user to the PHP page and then redirect them back to the original page. But calling the script via AJAX might be more preferable. Commented Sep 23, 2012 at 11:44
  • You can use loading page in iframe: stackoverflow.com/questions/5142825/… Commented Sep 23, 2012 at 11:47

3 Answers 3

2

Nothing that is well supported or practical.

Ajax is just shorthand for "Making an HTTP request from JavaScript without leaving the page".

PHP is heavily geared towards being a server side web language (so it is optimised for being accessed over HTTP). Browsers are focused on accessing content over HTTP.

Sign up to request clarification or add additional context in comments.

3 Comments

Please correct me if i'm wrong. Is XMLRPC an another approach?
@4lvin — No, it is a subset of the same approach. XMLRPC involves sending XML over HTTP. If you were doing that from JavaScript in a browser you would use Ajax to do it.
Eh, ok. Got it ;) Thanks for the explanation. I was confused with them.
0

No, you use a XmlHttpRequest (that is, I assume you don't want the user to experience any sort of page refresh).

To work cross browser easily I'd recommend using a library like jQuery which handles everything for you, everything is nicely encapsulated and abstracted so you don't need to worry about any of the details. That way calling your script becomes extremely easy.

1 Comment

Please correct me if i'm wrong. Is XMLRPC an another approach?
0

XMLHttpRequest is the best way, as far as I know, but there are other techniques too. There is the old school way some sites still use. Using hidden iframes and sending request through it.You create an iframe with javascript, append it with 0 width and height and the request the php file. The output must be script that somehow communicates with the parent window script.

3 Comments

Those are both methods of performing Ajax.
However the iframe one doesn't use the XMLHttpRequest. So I wouldn't agree with calling it AJAX. The need for ajax arose when web designers started using hidden iframes
Nothing about Ajax requires the use of the XMLHttpRequest object. XHR, hidden iframes, JSONP, it's all Ajax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.