Ajax response is fine but in error method - javascript

I'm facing a problem in ajax call. When I have called to given URL, Everything is fine but it is coming in error method of ajax response,
Code is below
$.ajax({
url: "My_URL",
Method: "Get",
async: false,
success: function(msg){
console.log("success");
console.log(msg);
},
error: function(msg){
console.log("error");
console.log(msg);
}
});
Please see the attached image which is fine but response in error method. Why ?
Any can guide me please ?

Related

Web API Not Returning data using JQuery Ajax

I am newish to JQuery Ajax.
My code below always return the error function. Am I doing something wrong? I can see the json data in the response header using firebug I can't get the success function to work.
var url = "http://ec.europa.eu/budg/inforeuro/api/public/monthly-rates"
$.ajax({
crossOrigin: true,
type: "GET",
crossDomain: true,
async: false,
url: url,
dataType: 'jsonp',
jsonpCallback: 'jsonCallback',
contentType: "application/json",
success: function (data) {
console.log("Success");
},
error: function () {
console.log("Ajax Error Occurred");
}
});
Are you sure the source you're using the JSONP request on actually supports JSONP?
When calling the url http://ec.europa.eu/budg/inforeuro/api/public/monthly-rates?callback=foo (note the callback param) the response from the server does not contain a valid JSONP response (which would contain a call to the foo function).

Send a success response to POST request

I've got the following ajax call:
function sendRequest(quote, author){
$.ajax({
type: "POST",
url: window.location.pathname,
data: {quote: quote, author: author},
dataType: JSON,
success: function(){console.log("Data sent!");},
error: function(error){console.log("ran into an error")}
});
}
And here is my server (using express) handling the post request,
app.post("/", function(req, res){res.status(200).end("Success!")});
However, the console doesn't print "Data Sent". Instead, it prints "ran into an error"
Everything else is tested and is working correctly
First of all dataType should be 'json' not JSON
Then check the console log for specific error.

ajax https request jsonp success callback not working

Im run this script on my http site, on network tab show what request 200 ok,
but success callback not runing
$.ajax({
url: 'https://seobudget.ru',
success: function(data){
alert("123")
},
crossDomain:true,
dataType:"jsonp"
});
im try remove "crossDomain:true" but its nothing change
$.ajax({
url: 'https://seobudget.ru',
dataType:"jsonp",
success: function(data){
alert("123")
}
});
you put dataType in wrong place

ajax function not fetching url

I have:
function makeAjaxRequest() {
var url = '/queryjob/dbname/ip';
$.ajax(url,
{
success: alert(response)
});
}
When I do a normal browser request on this url I get a response of 43(just a test response right now)
When I click the button I have to run this function, nothing happens. I don't see a get request in the log at all. Do I have some stupid syntax error or something? I am pretty new to js and ajax. I have another function that works where I get a url and act on the html response code, but this one is killing me so far.
You are not calling $.ajax correctly. Assuming you wanted to make a GET request, this is the correct syntax:
$.ajax({
type: 'GET',
url: url,
success: function(response) {
alert(response);
}
});
You could also use $.get to accomplish the same thing:
$.get(url, function(response){
alert(response);
});
$.ajax({
type: "GET",
url: "/queryjob/dbname/ip",
success: function (data) {
alert(data);
}
});
Yes, it was a syntax error ;)

Unexpected token from webservice

I got this little snippet where I call a Battlefield 3 stat server. If you visit this URL, which I'm calling, we'll be getting no errors:
http://api.bf3stats.com/pc/server/?output=json&id=534f7035-cef8-48aa-b233-8d44a0956e68
But when I try to get the stats via Ajax call, I get:
Uncaught SyntaxError: Unexpected token :
... In my console I can see that the response is coming in, as when I visit the url, but I can't get the data with the ajax call... Is there something wrong with my code???
$.ajax({
type: "GET",
url: "http://api.bf3stats.com/pc/server/?output=json&id=534f7035-cef8-48aa-b233-8d44a0956e68",
dataType: "jsonp",
success: function(response) {
console.log(response);
}
});
Thank you in advance...
I'm not entirely sure, but it seems like that server is reporting 500 Internal Server Error when getting it via ajax. I've tried a number of different methods, and they all have 500 Internal Server Error returned.
That site seem to be unresponsive at certain times. Interesting also that the JSONP datatype did not work in Firefox. I've added a simple check to the response here.
$.ajax({
type: "GET",
url: "http://api.bf3stats.com/pc/server/?output=json&id=534f7035-cef8-48aa-b233-8d44a0956e68",
dataType: "json",
success: function(response) {
if (response == null) {
alert ("An error has occurred!");
} else {
console.log(response);
}
}
});
}

Categories

Resources