I've got a bit of a strange issue with iOS safari and backbone.js.
I am trying to fetch a collection via a post command, my backbone code is
MyApp.search_results.fetch({data: data,type: 'POST',
success: function(response){
//I do a bunch of stuff with success
},
error: function(){
alert('problem getting search');
}
});
when I run the above code in chrome (both desktop and in iPhone or Android) I get the result no problem.
But using safari on iOS, I get Failed to load resource: the server responded with a status of 404 (Not Found).
The big problem is my rails console does not even show that safari is sending the request, I see nothing past the previous request, so I'm getting a 404 error, but that actually isn't the problem.
Any ideas?
------------------------ update -----------------------
the problem is somehow caused by the type: 'POST'. I have removed and am now submitting a get request, but I would prefer this being a post type. So any suggestions on how to fix that would be great.
Backbone internally set's the request method to GET for the fetch function. Trying to override it can cause any number of inconsistencies and is not recommended.
If you're trying to fetch data, then why not update your server code to read the GET params instead of POST params (or both)?
Related
Very new to react so bear with me. I have got a webapi that on its GET it returns a redirect response, I believe the http code is 301.
How do I in React make my browser redirect to the webpage that coming from my api using fetch after a buttonclick?
I thought it would be as simple as just getting a fetch and not doing anything with it, but clearly nothing is happening
handleSubmit(event){
event.preventDefault();
fetch("https://localhost:44323/Redirection")
}
I have a program written in angular, and because im doing something in the browser that takes some time im getting 504 gateway timeout...how can I make the timeout bigger?
This is an error message produced by the server and needs to be fixed there.
See for example https://www.scalescale.com/tips/nginx/504-gateway-time-out-using-nginx/
This error is coming from service, you cannot handle from UI. This needs to be fixed from backend. However you can handle this kind of errors in UI.
.success( function( data, status, headers, config )
status will give you all status codes.
For more Info click here
I am trying to send a HTTP Post method from IE11 but it's not working. When Fiddler is open it detects a protocol violation: "Content-Length mismatch : Request header indicates X bytes, but client sent 0 bytes". It's working on Chrome, and I can't find a reason why it won't work in the IE11. I make the call using angular resource (In case it matters).
Thanks :)
Me and my friends realized what the problem is. IE Has a problem with location.reload(true) for an unknown reason. Instead we injected angular's $route and reloaded the page using the function $route.reload()
I want to create one custom 404 page for all errors coming to the website for production environment. For example if I receive missing controller or view error then it will redirect to
http://example.com/404.html, Also in some cases I will deliberately redirect it http://example.com/404.html
Earlier in CakePHP 2.x it was done by adding following action in AppContoller.php
public function appError($error) {
$this->redirect('/page-not-found.html',301,false);
}
But It is not working in CakePHP 3.x, I want to replicate same behavior in CakePHP 3.x
Do not redirect
The correct action to take if a page should render a 404 is to render a 404.
Redirecting to another page is confusing for users, especially since many browsers cache 301 responses making the original url inaccessible. This also affects e.g. search engines as the static file 404.html will have a 200 response code (unless you modify your webserver config) so it'll say 404 but simply not be.
The blog tutorial, which all devs should do before starting a project, guides you in the right direction:
public function view($id)
{
$article = $this->Articles->get($id);
$this->set(compact('article'));
}
The table method get returns a single entity object or throws an exception:
If the get operation does not find any results a Cake\Datasource\Exception\RecordNotFoundException will be raised. You can either catch this exception yourself, or allow CakePHP to convert it into a 404 error.
The controller code in this example doesn't need to have any "what if it doesn't exist" handling because by default if the record doesn't exist the result is a 404.
Changing the 404 template
If you want to change the way the 404 or 500 pages look change the template files
For all 4xx and 5xx errors the template files error400.ctp and error500.ctp are used respectively.
The error template is in your application, note that in production mode the output is very minimal.
If the get operation does not find any results a Cake\Datasource\Exception\RecordNotFoundException will be raised. You can either catch this exception yourself, or allow CakePHP to convert it into a 404 error.
The simplest way can be just implemented in two steps,
Step 1:
turn the debug mode off in config/app.php
Step 2:
Replace the content of src/Template/Layout/error.ctp with your custom layout.
In an Angular JS app I'm working on, I am using a service to periodically (in a $timeout) make a GET request to a URL in my API (both the Angular app and the API are being served from port 5000 on localhost).
For some reason, it appears that $http is not actually sending the GET. For each $http.get(), the .error() is called with empty data and a status of 0. When I check in my server log (I'm running a Ruby on Rails backend with the Unicorn gem for my server), it appears that the server never receives the request from Angular.
Here's the function in my service:
updateUserStatus = () ->
$http.get('/api/v1/status').success (statusData) ->
# update the variable and notify the observers
this.userStatus = statusData
notifyObservers()
startStatusTimeout()
.error (error, status) ->
# if there's an error, log it
console.log 'error:'
console.log error
console.log status
startStatusTimeout()
What's really odd is that it only happens sometimes. When it stops working, I can change the URL in the $http.get() to '/api/v1/status.json', and it works. For a while. Then I switch it back and it works again, for a while... obviously there is some greater issue at play.
I've been racking my brain for a few days now, and I've seen a bunch of similar issues on SO, but they all seem to be solved with implementing CORS in Angular, which I don't think is applicable to my situation because it's all coming from localhost:5000. Am I wrong? What's going on?
For reference, I'm using Angular version 1.0.7.
I had the same problem.
Check your code to see whether this happens after events that are fired from the DOM and are unknown to Angular.
If so, you need to add $scope.$apply(); after the get request in order to make it happen.
I'm fairly new to Angular so I'm not sure this is the best practice for using Angular, but it did work in my case.
See this similar question for a better explanation.