2
I have a system as below: HTML on the client side, Javascript and PHP on the server side. The idea is to have a kind of Webservice, where an HTML page (it has to be HTML because it will run in an app made in HTML5 with Intel XDK) prompts information to the server, where it is PHP that makes the return.
The problem: When I run this way, the result is the PHP code, as below, IE, the server did not process anything, returns everything that is written in the PHP file.
<?php
echo $data = date("d/m/Y H:i:s ");
?>
If I carry index.html
on the same server where the other files are, then the return is the date, which would be expected, IE, only runs if it is all on the same server, but what I need is a remote HTML file, running on any computer that accesses the PHP/JS service on the server.
What’s wrong with this setup? There’s a more practical way to do this?
On the local computer (C:/
), I have the HTML file with the code:
<html>
<head>
<script src="http://code.jquery.c...n.js"></script>
<script src="http://www.example.c...S.js"></script>
</head>
<body>
<a href="javascript:test();">Clique aqui...</a>
</body>
</html>
Server-side http://www.example.com
i have a Javascript and a PHP:
Javascript file:
function test() {
var jqxhr = $.ajax( "servidor.php" )
.done(function(response) {
alert( "success" );
alert(response);
})
.fail(function(response) {
alert( "error" );
alert(response);
})
.always(function(response) {
alert( "complete" );
alert(response);
});
}
PHP file:
<?php
echo $data = date("d/m/Y H:i:s ");
?>
Updating
I tested it in some situations, and now I’ve located where the problem is that I can’t get back from PHP. It is in the JS address, which cannot reach the PHP file on the server.
So it doesn’t work:
$.post('http://www.iodasistemas.meximas.com/JSON/servidor.php',
{comando:true}, function(data){
That’s how it works:
$.post('servidor.php', {comando:true}, function(data){
In short, the whole point is that HTML always calls JS, but it can’t get into PHP. Whether it’s running all the files on the server, or a loose HTML on the computer. The error I mentioned occurred because I had a.php server file in the same local HTML folder, so it was this file that it read, not the server one. It seems that when loading the JS, it goes to work locally, and does not wheel remote.
How to Get Javascript Into PHP using a full address http://....
?
I know it sounds absurd but, the server where PHP files are has PHP installed?
– Bruno Augusto