I'm looking to make a JSON request to an API and receive a response. I tested it using Postman and successfully received the following response:
JSON request to API:
{
"apikey":"&^$%#@!jwebdpqodp9fgkwjebfkdpqihdqlwkndqp"
}
The response I received in Postman is as follows:
{
"status": 200,
"result": {
"winner": "s",
"options": {
"1": "mar",
"2": "feb",
"3": "jan",
"4": "aug"
},
"question": "how old are u?",
"answer": 3
}
However, I encountered an issue when trying to send an AJAX request and receive a response. I attempted the following code, but it did not return any response:
var data = {"apikey":"&^$%#@!jwebdpqodp9fgkwjebfkdpqihdqlwkndqp"};
$.ajax({
type:'post',
dataType:'json',
url:'http://207.154.251.233:8039/app_dev.php/question/get',
data:JSON.stringify(data),
success:(function (response) {
alert(response);
})
})