below ajax call throws error message. I can't figure out what is wrong. Thanks
$('#filterform input:text[name=other_location]').bind('keyup', function() {
var val = $('#filterform input:text[name=other_location]').val();
$.ajax({
url: 'http://linkedin.com/ta/region?query='+val,
//contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){
alert('success');
},//success
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("XMLHttpRequest="+XMLHttpRequest.responseText +"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
}
});
});
What you need is JSONP
dataType: "jsonp"
Related
var object={
"longDynamicLink": "https://[APP_NAME].page.link/?link=[LINK_HERE]",
"suffix":{
"option":"SHORT"
}
}
$.ajax({
url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=[KEY_HERE]',
type: 'POST',
dataType: "json",
data: object,
success: function(response, textStatus, jqXHR) {
alert(response.shortLink);
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus, errorThrown);
}
});
The above code works if the "suffix" is deleted from the request. That makes an "UNGUESSABLE" url, but I want a short URL. As stated in the documentation at https://firebase.google.com/docs/dynamic-links/rest?authuser=0 I added the suffix option parameter, but it results with a 400 response. Any ideas why?
I haven't ever tried this but, ...
POST https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=api_key
var params = {
"longDynamicLink": "https://example.page.link/?link=http://www.example.com/&apn=com.example.android&ibi=com.example.ios",
"suffix": {
"option": "SHORT"
}
}
$.ajax({
url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=[KEY_HERE]',
type: 'POST',
data: jQuery.param(params) ,
contentType: "application/json",
success: function (response) {
alert(response.status);
},
error: function () {
alert("error");
}
});
I am using cordova and while doing json i am getting an error "Failed to load resource: the server responded with a status of 400 (Bad Request)".
But the same code when I run it on postman is getting the right answer.Please help me to solve this problem.
The code is:
$.ajax({
url: url,
type: "POST",
async: false,
ContentType: "application/json; charset=utf-8",
data: jData,
dataType: "json",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
},
});
And a screenshot of the right answer on the postman is also given for your reference
you need to stringify the JSON data was sending
$.ajax({
type: 'POST',
url: url,
async: false,
data: JSON.stringify(jData),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(response) {
console.log(response)
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
Try removing the open and closing brackets around your jData
var jData = {};
Not
var jData = [{}];
function GET() {
jQuery.support.cors = true;
$.ajax({
url: 'http://localhost:32253/api/UserDetail/GetRoleDetails',
type: 'GET',
async:true,
contentType: "application/json",
dataType: 'json',
xhrFields: {
withCredentials: true
},
error: function (xhr, status)
{
alert(status);
},
success: function (data) {
alert("Success!");
}
});
return false;
}
I am very much new to ajax,I tried a ajax call to my services method which returns value.But the success callback function is never fired .I only get error.What might be the reason?
I tried using dataType to jsonp and other similar solutions which had been found in Stackoverflow regarding this issue.Nothing worked out.I am getting server response as 200 oK.
try this code
$.ajax({
type: "POST",
url: URL,
async: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonp: "onJSONPLoad",
jsonpCallback: "newarticlescallback",
crossDomain: "false",
beforeSend: function (xhr) {
},
error: function (request, status, error) {
console.log("Error In Web Service...." + request.responseText);
return false;
},
success: ajax_success,
complete: function (xhr, status) {
}
});
create function "ajax_success" in ur page
like below
function ajax_success(parsedJSON) { //you code here
}
this may be help you
try this code
$.ajax({
type: "POST",
url: URL,
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonp: "onJSONPLoad",
jsonpCallback: "newarticlescallback",
crossDomain: "false",
beforeSend: function (xhr) {
},
error: function (request, status, error) {
console.log("Error In Web Service...." + request.responseText);
return false;
},
success: function (data) {
Result = data;
},
complete: function (xhr, status) {
}
});
I am using jQuery 1.11.3 with the following code:
$.ajax({
type: "GET",
data: {
apikey: apiMusixkey,
q_track: q,
page_size: 10
},
url: "http://api.musixmatch.com/ws/1.1/track.search",
dataType: "jsonp",
contentType: 'application/json',
success: function(data) {
//console.log(json);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
I am getting the error:
parseError... [] was not called
What am I doing wrong?
Looks like you are missing a few things on your ajax. You need to specify the name of the callback function to handle the jsonp. Also, there's a format parameter you need to use with the musixmatch api. Checkout this plunker: http://plnkr.co/edit/XW6TFUJquW8o8EVpEEgU?p=preview
$(function(){
$.ajax({
type: "GET",
data: {
apikey:"309788821d050a0623303261b9ddedc4",
q_track:"back to december",
q_artist:"taylor%20swift",
f_has_lyrics: 1,
format:"jsonp",
callback:"jsonp_callback"
},
url: "http://api.musixmatch.com/ws/1.1/track.search",
dataType: "jsonp",
jsonpCallback: 'jsonp_callback',
contentType: 'application/json',
success: function(data) {
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
});
I have the following ajax call. I want to send out the data in jason format. However I noticed in Fiddler that the data is converted to query string parameters. What I am doing wrong?
$.ajax({
type: "GET",
url: "StatusService.svc/CheckStatus",
data: JSON.stringify({"companyName":"paymins"}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('ok!');
alter(data.toString());
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus + ' / ' + errorThrown);
}
});
Change the type of your request to a post.
$.ajax({
type: "POST",
url: "StatusService.svc/CheckStatus",
data: JSON.stringify({"companyName":"paymins"}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('ok!');
alter(data.toString());
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus + ' / ' + errorThrown);
}
});
Get cannot contain a body. Use post for that.