I think all this is just a confusion on your part.
If request.php
is a file and your jQuery and scripts are on another page, because if they were all in the same file, the return of the variable dados
in function
would show in console something like it all :
Yes,itwouldreturntojavascriptandhtmlasastring
,sincethecurrentpagewouldberequestingitself,butifitdidnotreturnthenitisbecausedifferentpagesanddifferentPHPscripts,ifthisisthecaseitisverylikelythatyouarenotpointingafilecorrectly.
Practicaltestwith$.get
($.ajax
):
Createthefollowingfiles:
foo.php
<?phpvar_dump($_GET);
baz.html
<!DOCTYPEhtml><html><head><title></title><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<p>Oi</p>
<script>
$.get("foo.php", "dados=dados", function(dados) {
console.log(dados);
});
</script>
</body>
</html>
Both should be in the same folder and should not change anything, the result I did returned exactly this:
Otherpossibleissues:
VersionofjQuerywithBUG
MaybeinyourpageyouareusingaversionofjQuerythathasabug(ithasalreadyoccurredtome),Irecommendthatyouupgradetothelatestversion(inthiscaseyoucanchoosebetweenmajorversionsjQuery1,jQuery2,orjQuery3),incaseIuse1.12.4:
link
For other versions see: link
Problem of some plugin that is using ajaxSetup
If you happen to be using $.ajaxSetup
it might affect the behavior of all jQuery calls, I recommend that you remove exist and test again.
As a test do this:
$.get("request.php?dados=dados", function(dados) {
console.log(dados);
});
And see if it still crashes
Problem in installing PHP and Apache
To be sure it's a problem installing the server so you can take a real test try to access request.php
directly, for example:
If it works hard, the problem will be in the server installation.
You did not understand what HTTP is
As I asked, you could read the links that tried to explain the best I got about how it works Requests and Answers, I think you should be messing with this and if you read the links calmly you will understand well where you are failing, this because HTML and JavaScript do not "communicate directly" with PHP:
Summarizing a little:
You have to understand some things first:
-
front-end
The front end is a relative term, but in practice it is usually used to refer to what will be rendered in the browser
-
back-end
The back-end is also relative, but in practice it is generally used to refer to general server-side technologies such as database, HTTP processing program (like Apache and IIS), and dynamic language and frameworks
-
HTTP request
This is what the browser sends to a server, it occurs when you type a URL in the navigation bar, when you upload a
-
HTTP Response
The HTTP response is generated after an HTTP request and it will respond according to the request of this request
PHP is a language that can be used (and is usually used) for web pages, it runs on the side that we call the back end, the browser communicates with the server through the HTTP protocol making a request, then PHP processes a script and generates a response, this all occurs on the server and not on the user's machine, every line or entire generated content will be sent as an "HTTP response" to the browser you requested, for example:
Inotherwords,PHPdoesnotrunnexttoHTML,itgeneratesaresponsethatcanbeaHTML"document", such as a TXT, an image, a video, will depend on what you set PHP to send response .
I know that the linked answers do not solve your problem, but your problem is probably your confusion about not understanding the layers.