ajax https request jsonp success callback not working - javascript

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

Related

Ajax response is fine but in error method

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 ?

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).

No success call for JSONP request if one of the multiple calls fail

Here's the problem in an abstract way, I have multiple IPs. I want to figure on which of the IPs the server lies. The server hosts a json file to help with JSONP request.
for (index = 0; index < ipArray.length; ++index) {
var ip = ipArray[index];
$.ajax({
url: utils.getJSONPRequestURL(ip),
jsonpCallback: 'callback',
dataType: "jsonp",
success: function (data) {console.log(this.url)}
});
}
The above function works fine if the IPs are not reachable, it will call the success function which prints the url that succeded. However if one the calls return net::ERR_NETWORK_ACCESS_DENIED error. I will not get a success callback at all.
Please note that if i remove jsonpCallback option from the ajax request and define
window.callback = function(data) {console.log(data)}
This will get called in spite of the above mentioned error, however I will not know on which URL did I get this callback from.
Thank you in advance
Try the following modification to your ajax function:
$.ajax({
url: utils.getJSONPRequestURL(ip),
jsonpCallback: 'callback',
dataType: "jsonp",
success: function (data) {console.log(this.url)}
}).done(function(){
console.log("done");
});
The done function should fire regardless of the call's success.

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 ;)

Perform GET request using jquery

I need to perform the following GET request,
telnet somesite.com 80
GET /index.html HTTP/1.0
using javascript, jQuery.
I've tried to follow the instructions in this site in particular the following code:
$.ajax({
url: 'http://somesite.com',
success:function(data){
alert(data);
}
});
but It doesn't work!
Where am I wrong?
Try this one:
$.ajax({
type: "GET",
url: "http://somesite.com",
timeout: 300000,
contentType: "application/json; charset=utf-8",
success: success,
error: failure
});
function failure(response) {
alert(response);
}
function success(response) {
alert(response);
}
by your code im assuming you are doing a cross domain ajax request. Which are automatically blocked by the browser.
you can either use the allow domain header using Cors see this Cross Domain Get Request in JS/JQuery
or switch to JSONP
If you want to perform a cross domain request try this
Working DEMO
You can use this in your head tag
<script src="https://rawgithub.com/IonicaBizau/jQuery-cross-domain-requests/master/js/jquery.xdomainajax.js">
</script>
code
$.ajax({
url: 'http://somsite.com', // Or your web page link
type: 'GET',
success: function(res) {
alert(res);
}
});

Categories

Resources