I have read similar questions on this site, but none that I can find matches my problem closely.
I manage a joomla 3.5.1 site and I wrote a javascript that, when I press a button, sends a mail by asynchronously calling a php page that I placed on the joomla root.
The php file echoes a result ("Mail sent" or the content of an exception, with a try/catch structure).
Let's say the function works properly and the echo inside the catch runs (then exits).
echo "Mail sent";
exit();
The AJAX call should set the inner html of a span to "Mail sent"
$ajax({
url: 'phpname.php',
type: 'POST',
datatype: 'text',
data: 'option=com_ajax&a1=mail&a2=from&a3=...',
success: function(data){
$('#container').html(data);
}
console.log(data);
}
As you can see, the datatype is text (I also tried json or html, with no discernible results), yet console.log gives me this:
<!DOCTYPE HTML>
<HTML><BODY>
Mail sent
The html of the resulting div as seen in chrome inspector is
<span>
Mail sent</span>
Of course, when I implement an if/else inside the success part of ajax in order to color that text green if it is "Mail sent" and red otherwise, I always get red text.
When I tested the php and js files outside joomla, they worked fine. I used no option=com_ajax then, but apparently joomla needs it.
How should I proceed?