I have been tweaking this script for a while and as I had mentioned in the question, my code works just fine in the non-asynchronous mode, whereas when I change async:true
, the code just fails.
Here is my code.
$.ajax({
type : "POST",
url : "http://someotherserver.com/sendmail.php",
data: { resp: data },
async: false
})
.done(function( msg )
{
alert(msg); // Works when async:false
})
.fail(function(jqXHR, textStatus)
{
if(textStatus == 'timeout')
{
alert('Failed from timeout');
}
});
There is nothing much in the sendmail.php
which resides on my friend's server with CORS
enabled there.
sendmail.php
<?php
file_put_contents('request.txt',json_encode($_REQUEST));
echo "filecreated";
The problem is when I change the async : true
, the request.txt file never gets created on that server whereas if I change async : false
it works as expected.
The thing is I want this request to be asynchronous , not synchronous.
Can somebody have any thoughts on this? If anymore information needed, I will be ready to provide.