I’m using AJAX / JQuery all over my site, so I KNOW that works.
I’m going through my PHP tutorial, and the current lesson is on coding and decoding JSON arrays. So I set up an example array in Javascript, stringified it to post is as JSON to the PHP. The same AJAX / JQuery code posting form data works fine. This isn’t working.
I’m not getting an error message of any kind. I’m just getting NOTHING. It never even calls the success callback function.
function jason_array(where) {
console.log(“In jason array”); // I see THIS.
var fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya", "Pear", "Plum", "Pomegranate", "Nectarine", "Grapefruit", "Tomato"];
var json_fruit = JSON.stringify(fruits);
console.log(json_fruit); // I see THIS.
$.ajax({
url: "php/examples.php?lesson=json",
method: "POST",
type: "POST",
dataType: "json",
data: {fruit:json_fruit},
contentType: "application/json",
success: function (data) {
console.log("In success function"); //I do NOT see this or anything else in the console.
let locMsg = "";
locMsg += "Raw Data=" + data + ".<br>";
let jfruit = json.parse(data);
for (let i=0; i < count(jfruit); i++){
locMsg += i+") "+jfruit[i]+"<br>";
}
func_printme(where, locMsg); //Internal function to insert HTML to the specified DIV.
}
});
What may help is to open the Developer Tools in your browser and check the Network tab. When the AJAX request is initiated, you should see the request show up there. From there, you can check if the request data is what you expect, whether the URL is correct and whether the response from the PHP code is successful and what you expected.
If your code never enters the success callback, it might just be that your request wasn’t successful. If that happens, then the error callback is executed.
This is live on the site right now so everyone can test it. Hidden by MOD → (NavBar) Education → PHP
Advanced → JSON Parsing
This is the “JSON Array” button.
The network tab is showing status 200 (ok) for that request.
It’s showing the data that was sent back which is what I was expecting from the PHP.
It’s just not running the success callback.
Hmmm…
and I see that you also have the file upload option ( as a tutorial )
Please delete my files and make sure such holes will not be possible !
Ssomeone will make some drama and your acc will be closed and you will be blamed.
in your case, it is also dangerous to see the contents of folders
so you can handle it like this:
If you do not want people to see the contents of your folders
create in root of htdocs file named .htaccess
and put this code in it
# Disable Directory Listings in this Directory and Subdirectories
# This will hide the files from the public unless they know direct URLs
Options -Indexes
use monstaFTP (file manager) from the client area
because many text editors can add BOM or wrong charset
or create a dummy index.html file (in every dir in which you wish)
purely to serve something instead of listing
I’m ordinary user as you are
only in addition, I have a moderator status on this forum
htdocs folder of your XY.rf.gd.
directly in it, not in some subfolder
that’s what I mean when I say in the root of htdocs
it’s not a matter of uploading, but monstaFTP also has an edit function
and with it you can create a file called .htaccess
and then edit it in the way of the paste code I gave you plus save.
for example you type in the address bar of the browser
your domain/php/
and a list of all files is obtained
which can be useful to a malicious person
when used option from the tutorial writing to file
if the content is listed
then he easily finds the name of the file in which to write bad code
or anything else in terms of gathering information