My application url : http://localhost/ctsubagent/
My Ajax Code :
...
$.ajax({
url: base_url + 'hotel_booking/hotel/search_hotel',
type: "post",
...
When I click button to run ajax, in consolle exist error like this :
http://localhost/subagent/hotel_booking/hotel/search_hotel 404 Not Found
It appears that it was not calling ctsubagent, but it was calling subagent. This is causing the error.
It seems like there should be set in the config. But I do not know. I've tried it, but have not been successful.
Any help much appreciated
Cheers
Related
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.
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.
My desired outcome is to get air quality data on my web app.
I'm trying to use the airnowapi API to obtain the data. I use an URL they provided here, but my code fails to retrieve the data.
Here's a sample code of what I'm trying to do.
$.ajax({
url: "http://www.airnowapi.org/aq/observation/latLong/current/?format=application/json&latitude=38.3651&longitude=-114.4141&distance=250&API_KEY=[API-KEY]",
method: 'GET',
dataType: 'jsonp',
success: function(data) {console.log(data);},
error: function(){console.log("fail");}
});
It logs "fail" instead of logging the data. How can I remedy to that?
When I copy-paste the url in my browser, it downloads the .json file correctly, but I was expecting seeing it directly in the browser instead. I'm not sure if this is the origin of the problem.
Thank you!
PS.: This is my first time posting.
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/
How do I get more information about the errors in my Ajax requests?
When error occurs in Django during a normal HTTP request, Django shows a descriptive error page with exception details.
However, when error occurs during an AJAX request, I just know the HTTP error code and that's it. I'd like to know as much details as I learn from a Django error page.
Handle errors within your ajax request and use responseText to get the response text and put it into an empty div that you have created for that.
For example:
$.ajax({
url:"{% yourView %}",
dataType: 'json',
success: function(jsonData){
alert("Hooray!");
},
error: function(jqXHR, textStatus, errorThrown){
$('.errors_div').html(jqXHR.responseText);
}
});
The django error page will be rendered into div class=errors_div
Your web server's error log will contain additional information about any uncaught exceptions.
Use Firebug. In Console you'll see the AJAX request, just right click -> Copy Response Content and save that as an HTML file.
Why not access the url directly in your browser's address bar so you see a normal traceback?
Wrap it in another view to change the MIME type to text/html.
I also often have a view that wraps the JSON output in a html tag so the Django Debug Toolbar works correctly.