I have the following script that successfully completes an AJAX request:
var input = $("#input").val();
$(".pure-button").click(function() {
$.ajax({
type: "POST",
url: "script.php",
data: input
}).done(function(data) {
$("#output").val(data);
});
});
input
contains a string:
grant_type=refresh_token&client_id=abcd-efgh&client_secret=ijkl-mnop&refresh_token=qrst-uvwx
However, the .done()
does not seem to be working. Running the AJAX request in the Chrome Extension POSTMAN gives me the following output:
{"access_token":"123-456-789",
"token_type":"bearer",
"refresh_token":"987-654-321",
"expires_in":14399}
But how do I get this to display in #output
? It's a blank input field.
EDIT:
I thought it might be worth nothing that script.php
contains the following code:
<?php
header("Content-type: application/xml");
echo file_get_contents("https://api.example.com");
?>
If the echo file_get_contents()
is having any bearing on what is returned? Is my initial input string in an XML format? Is the POSTed data even reaching the other server?
2nd EDIT:
Changing my .done()
to alert(output);
gives me a pop-up containing nothing but null
. Seems like my PHP script (an apparent hacky way of getting around the Cross-Origin problem) isn't returning the request in a way that I can use.
var input = $("#input").val();
$(".pure-button").click(function() {
$.ajax({
type: "POST",
url: "script.php",
data: input
}).done(function(output) {
alert(output); // returns "null"
});
});