Hey guys, I am trying to pass a JSON object from my javascript file using ajax, to my php file so i can dynamically send an email.
However, on my console I am receiving an error message:
XML Parsing Error: no root element found
Location: file:///C:/Users/tekke/Documents/My%20Websites/fulledm/sendEmail.php
Line Number 6, Column 3:
Mind you, I am doing this on my local computer without a local server running, could this be the issue?
Well for starters, you’re telling PHP to var_dump the decoded JSON, which has an output that is NOT itself JSON, so you’ve got a content type mismatch between the header and the code.
But yes, the problem is because you’re referencing a file://, rather than localhost via a server.
Perhaps you are being a bit misled by the acronym?
AJAX - Asynchronous JavaScript And XML
vs. aka.
XHR - XML HTTP Request
The clue is the “HTTP Request”
How are you running your PHP? It is possible to run PHP from the command line, but it is not something I hear others discussing very often.
Another thing that doesn’t come up in discussions often is that PHP comes with a built in server
So even though it might be possible to run PHP exclusively from the command line, it would be unusual. And if you are going to use PHP to output to a browser (i.e. web pages) you will need a server other than the built in one.