3
Well I’m making a system, and I need to receive a php page variable every time, so I can work on it on my index.php page.
A friend of mine who understands more of ajax than I gave me the following code:
However, I don’t know how to pass the values of variable x in PHP (loading.php), for my Javascript on the page index.php
.
The code of my index.php page is like this:
<html>
<head>
<script src="jquery-3.0.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
$.get("loading.php", function(data) {
alert(data);
});
</script>
</body>
</html>
How can I do?
The PHP page
loading.php
has to be somewhereecho 'Alguma coisa...';
and so ajax picks up that string and sends it to callback. You know how to do that?– Sergio
From PHP, I mean a lot, so tell me one thing, if I want to receive 2 variables instead of one, I would echo 2x of the 2 variables, but then how I received them in javascript?
– Gonçalo
In this case it sends an array or an object.
echo json_encode(array('foo', 'bar'));
and in Javascript:JSON.parse(data);
or using a jQuery method for JSON.– Sergio
Could you give me an example? , I’m a little new at this ajax and json.
– Gonçalo