My ajax call just stopped working - ajax

I have been using ajax call to fetch data from my remote server on my cordova app/localhost, It just stopped working for no reason, but the same ajax call is still working locally, Im using wampserver to host my site locally,
Below is the code that fails to fetch data but it has been working just fine
$.ajax({
url: 'http://wingup.byethost4.com/trial.php',
type: 'GET',
data: {phone_number:"phone_number"},
success:function(data){
console.log("message was sent");
},error:function(err){
console.log("message was not sent");
}
});
But if i change the url to my localhost it works, Please help me with annoying error

It may have the error like this
CORS header ‘Access-Control-Allow-Origin’ missing
It does not allow remote access. Check this related setting on your server.

Related

Cross Origin Domain Blocking error with AJAX

Could anyone please tell me what I am doing wrong:
I'm using the following code and getting a Cross Origin Domain Blocking error. And no I don't have the ability to enable CORS on the Server Im getting data from. But when I use the URL by itself, I get the data I am after, it's just not working with AJAX, Im trying to use JSONP to get around the issue:
$(document).ready(function () {
$.ajax({
url: "https://serveraddress/remote-json.cfm?do=gettimetable",
dataType: "jsonp",
jsonpCallback: "logResults"
});
});
kind regards,
Brad
You can use back-end to solve this problem. This back-end(php, java, nodejs, curl...) implement a httpclient to getting data from any server.
I try to set "useDefaultXhrHeader: false", it is the configuration ajax.

Django Ajax post failed with Gunicorn and Nginx on AWS

I am writing a app using AJAX deployed by gunicorn and nginx on AWS.
It works very well when I am using python3 manage.py runserver. But after I used gunicorn, the AJAX post doesn't work. I get a Failed to load resource: the server responded with a status of 404 (Not Found).
What I did is a very simple AJAX post
$.ajax({
type: 'POST',
url: '/analytical-tools/getData/',
data: {
'somedata':somedata
csrfmiddlewaretoken: '{{ csrf_token }}'
},
dataType: 'json',
success: function (data) {
/*do something*/
}
});
First I want to ask is is there any difference on AJAX when deployed on Gunicorn?
And I want to ask how to debug on gunicorn. The gunicorn runs in the background and I can't see any debug information or print something when it is running.
404 stand for not found... and here is the question is the django endpoint available at all or not available for certain data?
1) if at all mayby the config nginx/gunicorn is problematic
2) if for certain data make sure this data are really there
3) idea make sure there is no crap in JS, e.g have a look into XHR section and copy the request load, and cross validate it in Postman
Regarding debuging, there should be files in logs with each request etc.
where uwsgi? https://www.digitalocean.com/community/questions/where-s-my-django-application-log-file
where nginx? Where can I find the error logs of nginx, using fastcgi and django

Sencha ajax call failing on device

A am trying to make a fairly simple ajax call to my server to handle login etc. the app is written using sencha, with phonegap. As far as I am aware, because phonegap sends all requests as file// cross-domain issues do not apply. However I am constantly getting failures when testing this on a real device. If I implement the sencha app as localhost then everything works fine (this is making a call to a different server). The call is successful etc. However when I build it in eclipse and port it to my phone, I always get a failure. the code I am using is below, but I don't think it is this because as I say, this works locally.
Ext.Ajax.request({
url: 'http://xxx/global/external_api.ashx',
timeout: 3000,
method: 'POST',
params: requestData,
success: function (xhr) {
alert('Success: ');
},
failure: function (e) {
alert("An error occured connecting to the server: ");
}
});
Anyone have any other thoughts?
Seems to be something to do with the newest 3.2 build.. reverted to 2.9 and it works fine.

How to get/post/delete/put information with jQuery and AJAX

I trying to do a DELETE, PUT, GET and POST a request with ajax and jquery.
The method POST works well by creating a new record, but I cannot make it work the other methods (PUT, DELETE and GET).
This is the code (it works fine, it creates the new record but it doesn't reach the "success" event):
var jsonExample = {"advertisement":{"title":"test"}};
$.ajax({
type: "POST",
url: "http://example.com/advertisements.json",
data:jsonExample,
success: function(response){
alert("test");
}
});
When I change the type "POST" to "DELETE" or "PUT" I have the follow error:
NetworkError: 404 Not Found
And when I change it to "GET" it throws the following message:
200 OK
But it don't any other responses. It should be something like this:
{"advertisement":{"created_at":"2012-04-17T13:20:17Z","from_age":null,"neighbourhood_id":null,"title":null,"date_to":null,"days":null,"promotion_id":null,"updated_at":"2012-04-17T13:20:17Z","date_from":null,"gender":null,"id":3,"display":null,"desc":null,"budget":null,"image":null,"to_age":null,"department_id":null,"town_id":null}}
The
Please note: my app is getting this info from a remote server, but I don't know if that has something to do with this problem. Because I've run it in Google Chrome and I've received the Access-Control-Allow-Origin message on the browser's console.
Any ideas?
You cannot make cross-domain AJAX requests using jQuery for security reasons. You may however be able to use jsonp providing that the URL you are requesting the data from is set up to handle jsonp requests.
This article should help you out alot more than I'm able to: http://www.fbloggs.com/2010/07/09/how-to-access-cross-domain-data-with-ajax-using-jsonp-jquery-and-php/

AJAX/JSONP Question. Access id denied using IE while requesting corss domain

Ok, Here we go. I have already searched the Stack for the answer i have found some useful info but i want to clear up some more things. I also search the net for the answer but no real help.
I have worked with some api (yelp, ouside.in). In yelp i use to inject the script to head with the url request to the api with a callback funcion. I worked fine in all browsers. But while using outside.in api when i call the url the callback in not working.
In yelp they have a url field can be used like that callback=callbackfuncion so the callback will automatically called.
But in outside.in there is not such field available. Is there are any standard command for callback function which will work regardless of any server/api?
I also tried a standard ajax request using jQuery $.ajax() function. It worked for my local pc for both IE and other browser but did not working in IE showing the error: access denied, other borwser seems ok. Firebug in my FF also don't notice any errors.
Outside.in has an javascript example but it is too hard to me to understand
github.com/outsidein/api-examples/tree/master/javascript/browser/
site i am working: http://citystir.com
yelp: yelp.com
outside.in: outside.in
Techniqual info:
i am using: wampserver in local, wordpress for hosting, Godaddy, apache for remote with linux.
Codes:
Using Jquery $.ajax
url is like: "http://hyperlocal-api.outside.in/v1.1/states/Illinois/cities/chicago/stories?dev_key="+key+"&sig="+signeture+"&limit=3
function makeOutsideRequest(url){
$.ajax({
url: url, dataType: 'json', type: 'GET',
success: function (data, status, xhr) {
if (data == null) {
alert("An error occurred connecting to " + url +
". Please ensure that the server is running and configured to allow cross-origin requests.");
}else{
printHomeNews(data);
}
},
error: function (xhr, status, error) {
alert("An error occurred - check the server log for a stack trace.");
}
});
}
Thanks!
This question was asked in the Outside.in developer forums this morning as well (presumably by the same person). Here's a link to that discussion: http://developers.outside.in/forum/read/97053
To summarize, the Outside.in API does not support JSONP, but CORS support is included in the next release of the API, which will hit in the near future.

Resources