2
There is how to send a PHP command via Ajax?
For example:
$.ajax({
url: 'index.php',
type: 'POST',
data: '<?php echo "teste"; ?>',
success: function(r) {
$('body').html(r);
}
});
In case, I’m still studying Ajax, I did not understand very well, I made this example code, but for example, what it does?
He sends what’s on data:
to url index.php or it takes the content of index.php?
If the answer is the second, then what is the date in ajax for?
But going back to my question, what I really wanted to know is if you have, send PHP command via Ajax.
How can I use a direct PHP command in Ajax? For example, without having to touch the file . php
– Lucas de Carvalho
@Lucascarvalho You want to send the result of the command, or the command to be executed?
– Francisco
in case, already execute the command. I guess this does not have how right? For example, send an echo and it automatically run.
– Lucas de Carvalho
Yes, it is exactly the way you are already doing it. But the file that ajax is in should be
.php
.– Francisco
Hi Francisco. I think I bumped into the cell phone screen and caused a -1 unintentionally in your answer. Only now the system only lets you withdraw if the answer is edited. Do not want to take advantage and put a danger alert in the part that speaks of Eval? ;)
– bfavaretto
@There’s something very strange about what you’re saying. By ajax you will always transmit text such as field values (or a file in case of upload). At most you can send PHP code (as text) and run with Eval as Francisco showed. But in 99.99999% of cases this is unnecessary, and can be extremely risky in terms of safety.
– bfavaretto
I saw it, I got it now. It sends like a "url," one for example? text=asdas I asked if you noticed, put was trying to send something like this to my server and did not know how it arrived there.[
– Lucas de Carvalho
@bfavaretto I’ve edited the answer.
– Francisco
@Lucas If you change the method from POST to GET in the code, the data is sent in the URL in the format you mentioned. With post is similar, but not in the URL, but in the body of the HTTP request.
– bfavaretto