I am trying to make an ajax call on the below url
http://postalpincode.in/api/postoffice/tindivanam
which works fine with chrome address bar.
but if i use
city = 'Tindivanam';
jQuery.ajax({
url: 'http://postalpincode.in/api/postoffice/'+_.toLower(city),
method: 'GET',
success:function(response){
console.log(response)
}
})
I am getting this
Related
I have a problem with a route. I declared the route as a post and the form has a post method,
but when I submit my form I get a 405 error. Also the allowed methods GET and HEAD. This is the AJAX call with the method post.
var form = $('#typeCreateForm');
e.preventDefault();
$.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});
$.ajax({
type: "POST",
url: "{{route('admin.type.store')}}",
data: form.serialize(),
success: function(data){
console.log(data);
}
});
Here is my route
// all routes name are prefixed with admin
Route::post('evenment/type/index/store','TypeController#store')->name('type.store');
I have an $.ajax request that hits and API. The API returns four cookies and then performs a (302) redirect.
$.ajax({
url: authUrl,
type: 'post',
mode: 'no-cors',
dataType: 'text',
data: dataObj,
})
.done(function (response) {
console.log('response');
console.log(response);
let myCookies = document.cookie;
console.log(myCookies);
});
I'm trying to get the cookies inside the $.ajax, but the redirect causes the code in the .done to never execute.
Even if I try to get the cookies in the console (where I can see the cookies and their values), I get nothing back.
This is happening inside a Chrome Extension, but even if I run this outside the extension I get the same result.
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!
Im making a Login whit facebook.
using the javascript sdk im geting the response (i guess is JSON), and i want to send this response to a php file to check if the user is in the database or not.
so heres what i got so far.
this is the function i call when the user is loged into facebook.
function testing(){
FB.api('/me', function(response) {
response = JSON.stringify(response);
//call another function, sending the data recived
ajaxlog(response);
});
}
and here is the ajaxlog function
function ajaxlog(facedatos){
$.ajax({
type: "POST",
url: "facebook-ajax-login.php",
dataType: "json",
data: facedatos,
success: function(response){
//the php brings the conect response true or false
if(response.conect==true){
$("#exist").html(response.data);
}else{
}
},
beforeSend: function(){
$("#exist").html("<img class='img-responsive ajax-l' style='width:40px;padding-top:10px;margin-right:10px;' src='images/ajax-loader.gif' />")
}
});//<!--ajax-->
im doing alerts and the facebook data comes with no problem. i think the issue is how i send the data by post, im not reciving the data in the php
I find the issue by myself,
the problem is that i was sending the post request whitout a name.
in the ajax function changed
data: facedatos,
for
data:{
face: facedatos
}
and in the php recived the data as $_POST["face"];
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.");
}
});