JQuery - Ajax - Set Request Header - DocuSign - ajax

Afternoon!
I a trying to send a get request usng jquery/ajax and I need to set headers. When I try setting the headers using Chrome's REST app, it woks fine and returns what I need.
I am watcing the headers in Firebug hen I run this code:
$.ajax({
url: urlLoginCall,
type: 'GET',
headers: {'Accept': 'application/json'},
success: function(r){
alert("success");
},
error: function(){
alert("failure");
}
});
The above works fine and I get a failed response, since I am not including the authorization info in the headers. But it at least shows me something in Firebug that I am setting the header Accept.
When I try to add the X-DocuSign-Authentication header, i get the failed alert, but nothing comes up in Firebug:
$.ajax({
url: urlLoginCall,
type: 'GET',
headers: {'X-DocuSign-Authentication': jsonLoginCall},
success: function(r){
alert("success");
},
error: function(){
alert("failure");
}
});
Any ideas would b helpful. Thanks!

Related

403 error on Ajax Post Laravel shared hosting

Site works completely OK on other hosting. That is also shared. But doesn't work on current hosting when an Ajax post request is made. The server(not app) responds with 403.
What should I do now? I used postman and it works okay. No problem in url also.
Update:
the code for ajax request:
$.ajax({
type: "POST",
url: window.location.href.split('?')[0],
data: data,
success: function(data){
window.location = data.redirect_to;
},
error: function(data){
},
dataType: 'json'
});
The problem was "not setting" content-type in headers.
I changed the code into:
$.ajax({
type: "POST",
url: window.location.href.split('?')[0],
data: JSON.stringify(data),
success: function(data){
window.location = data.redirect_to;
},
error: function(data){
},
dataType: 'json',
headers: {
'Content-Type':'application/json'
}
});
And it worked.

JS Cross-Domain request with JSONP

I'm trying to perform a cross domain call. so i'm using JSONP.
The problem is that the response is not json, but an html.
The request works fine and i see the response with status 200 in the network console, however the error function is the one being called, as the expected response is JSON whereas I get an html.
Do you have alternatives for using JSONP for cross domain request?
If i'm using JSONP but the request is not, can I somehow expect a value which is not a json? (tried dataType: 'jsonp text' and didn't work)
Although I get an error with the ajax call, is there a way to extract the result of the request, as it still returns status 200, it's just not accessible ?
$.ajax
({
type: "GET",
url: myurl,
crossDomain:true,
dataType: 'jsonp',
contentType: "text/html; charset=utf-8",
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
},
});

jquery ajax success not working

I got simple ajax call i could not get why it is not running success method despite the fact that chrome developer tools show that it is getting the response for the request.
$( document ).ready(function() {
var url_API="http://moviesapi.herokuapp.com/cinemas/find/"+"PL15RH";
$.ajax({
type: 'GET',
url: url_API,
dataType: "jsonp",
crossDomain:true,
success: function (response) {
alert(1);
}
});
});
The API doesn't support jsonp. You're getting 500 (Internal Server Error).
It does support JSON, but you're getting the classic No 'Access-Control-Allow-Origin' header is present on the requested resource CORS error. You need to explicitly send the Access-Control-Allow-Origin header on your heroku API:
Header property:
Access-Control-Allow-Origin: *
A more verbose solution: "No 'Access-Control-Allow-Origin' header is present on the requested resource"
try this:
jQuery(document).ready(function($) {
var url_API="http://moviesapi.herokuapp.com/cinemas/find/"+"PL15RH";
$.ajax({
type: 'GET',
url: url_API,
dataType: "json",
crossDomain:true,
success: function (response) {
alert(response);
}
});
});

cross domain request issue origin not allow

cross domain request issue
my ajax call code actually when i am running given url directly in browser it shows me json data but using ajax call it always shows me ajax error believe me i tried n follow many things no fruitful result from 18 days.
$.ajax({
crossDomain:true,
type: "GET",
url: 'http://taxihub.azurewebsites.net/Mobile/api/json.php?method=getCompanyList',
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: false,
success: function (data) {
console.log(data);
return;
},
error: function (err) {
console.log("AJAX ERROR");
console.log(err.responseText);
}
});
you can also check this link directly u will see json data coming but i found error i dont know why
"http://taxihub.azurewebsites.net/Mobile/api/json.php?method=getCompanyList"
error: OPTIONS http://taxihub.azurewebsites.net/Mobile/api/json.php?method=getCompanyList Origin lhost:809 is not allowed by Access-Control-Allow-Origin.
please help me i am stuck here from 18 days on this issue
Remove the cross-domain and content-type part and it'll work but you'll have to do a little extra string manipulation work to put it in JSON object:
$.ajax({
type: "GET",
url: 'http://taxihub.azurewebsites.net/Mobile/api/json.php?method=getCompanyList',
dataType: "json",
success: function (data) {
console.log(data.result.getCompanyList[0].CompanyID);
return;
},
error: function (err) {
console.log("AJAX ERROR");
console.log(err);
}
});
}
Actually it seems cross-domain doesn't have any effect with or without it. I guess the server you're targeting doesn't have strict cross-domain prevention but doesn't like the JSON content-type. I'd be glad to get a more specific explanation.
EDIT I used JQuery 1.10.2 if it matters

Ajax returning 404 error on ASP MVC3 site

This Ajax code works perfectly is I'm running the program on my local machine. However, once we put this out on a DEV server we get a 404 error. The site is an ASP MVC3 site that communicates with a SQL database, and the rest of the site has no problem doing so. I'm brand new to Ajax so I'm not quite sure where to look. Could this be an issue with IIS as well?
Ajax code
var request = $.ajax({
type: 'POST',
url: '/BatchPrograms/PopDetails',
data: { 'programName': pgmname },
dataType: 'text',
success: function (data) {
console.log(data);
alert(data);
//$('#data').dialog('open');
},
error: function (data) {
console.log(data)
alert("Unable to process your resquest at this time.");
}
});
Chrome's Console error message:
POST http://insideapps.dev.symetra.com/BatchPrograms/PopDetails 404 (Not Found)
send jquery-1.8.3.js:8434
jQuery.extend.ajax jquery-1.8.3.js:7986
GetProgramDetails BatchDashboard:51
onclick BatchDashboard:165
Chome's Network error message
Name (Path) Method Status (Text) Type Initiator Size Time (Latency)
PopDetails POST 404 Not Found Text/Html jquery-1.8.3.js:8434 1.8KB 21ms
/BatchPrograms Script 1.6KB 17ms
Try modifying url to
url: '#Url.Action("PopDetails", "BatchPrograms")'
Try using the Url.Action() helper to get the route from the Table Routes defined in your application.
var request = $.ajax({
type: 'POST',
url: '#Url.Action("PopDetails", "BatchPrograms")',
data: { 'programName': pgmname },
dataType: 'text',
success: function (data) {
$('#data').dialog('open');
},
error: function (data) {
alert("Unable to process your resquest at this time.");
}
});

Resources