During an AJAX photo upload, the POST request is sent with the photo and returned successfully. However, the server still has some resizing tasks to complete before the image can be displayed. I set a timeout to loop until the image can be found by setting its source to what it will be once the server processes the image.
All other browsers(Chrome/Safari/Firefox) work great by repeating the GET request and eventually find it. IE 10/11 send one GET, returns a 404 and won't send anymore requests.
I've also tried AJAX requests as GETs for the image, same thing.
Ideas?
Are you sure your get request isn't being cached? Try appending a random parameter to the request each get. This will make the browser think you're pulling a different uri and not use the cached response.
E.x. some site.com/source?ignoreme=1526353377
If using jQuery you can set cache: false in your $.ajax call as well. It basically does exactly what explained above for you automatically.
Related
Using Ionic framework 1,
Making request using $http.post(); but, in the console.. two requests are getting generated.
the first request doesn't contain the POST parameters and is blank , while the second request contains the POST parameters as passed to $http.post() method.
What could be the possible reason ?
May be it's checking if already cached resource is updated or not by making a blank request to the server, before making a request to load data.
But, I have not enabled any caching or anything. Everything is default.
The first request is the Request Method: OPTIONS request. It checks whether or not the actual request is safe to send. It is also called 'preflighted request'
so I'm using JQuery's .getJSON to get a JSON from an api, the request are made on my localhost to a remote server.
When I access the remote server from the browser itself the data is ok, but when I use JQuery's getJSON the data is different, like there are no cookies even though there are.
I've thought that it's related to the cross origion policy stuff so I've tried using "Ajax Cross Origin" and it didn't help.
So what happens is that for example, when I access the server via the browser, it returns (this is ok)-
{
"id": "7"
}
And when I use a JQuery's getJSON (this is wrong)-
{
"id": null
}
What makes it even weirder is that when I use Postman rest client then I get the right data.
TIA
First thing to do would be open the developer tools in the browser, before the getJSON request is made. Then (e.g. in Chrome) click on the Network tab. Find the Http Get request made for the getJSON call, and click on it. Inspect any errors, check that the cookies were sent correctly, check the response data, right click the Url and open in new tab, what result do you get?
I'm implementing my own http module.
As I'm reading the official node.js http module api, I couldn't understand a few things:
If the user is using the response.writeHead(statusCode, [reasonPhrase], [headers]) function, are the headers should be written immidiatly to the socket or are they first supposed to be saved as a member to the object? and then written only after .end() function?
What is the meaning of implicit headers that should be used whenever the user didn't use writeHead()? are they supposed to be set ahead? and if the user didn't set them? what should be the behavior? thanks
Answers:
Anything that you write into response either headers with writeHead or body with write is buffered and sent. You see they use socket buffers. They can only hold fixed amount of data, before being sent. The important fact to remember is that you can only set headers before you start writing the body. If you do, some headers will set for you by the http server itself.
Implicit headers are ones which you don't write specifically but are still sent. Setup a simple http server, by responding a request without setting any header. Then view the request headers opening the site in browser. There will be headers like Date, Server, Host etc which are added to every request automatically without user's volition.
I found answer for the first question, but still don't understand the second one.
The first time response.write() is called, it will send the buffered header information and the first body to the client. The second time response.write() is called, Node assumes you're going to be streaming data, and sends that separately. That is, the response is buffered up to the first chunk of body.
I'm trying to figure out if it's possible to create a script that will find out the user's http status code if it's 200 or 301 for a a script like this for example? Must be a user request status code and not how the server gets it :)
<script type="text/javascript"
src="https://google.com"
</script>
Is it possible?
edit: I read and researched more it might be possible with Ajax Requests?
The answer is sadly no.
In a cross-browser, end-user script (ie: one that doesn't use custom extensions/browser plug-ins), you can't read through past file requests, for HTTP-response header values.
If you make an AJAX call, you can read response headers for that particular request (not for any others).
So, in theory, if you wanted to know what the server-response was, you could make an AJAX request for the exact-same file as your script request used in its src attribute...
But not in this case.
In this case, unless your domain is google.com, your browser is going to prevent you from making that request (as AJAX calls need to happen from the same domain as the page the user is currently on) there are ways around that on newer browsers, but even in those cases, you'd need to own google.com so that your server was set to allow AJAX calls from mysite.com
i have a problem with a http post call in firefox. I know that when there are a cross origin, firefox first do a OPTIONS before the POST to know the access-control-allow headers.
With this code i dont have any problem:
Net.requestSpeech.prototype.post = function(url, data) {
if(this.xhr != null) {
this.xhr.open("POST", url);
this.xhr.onreadystatechange = Net.requestSpeech.eventFunction;
this.xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
this.xhr.send(data);
}
}
I test this code with a simple html that invokes this function.
Everything is ok and i have the response of the OPTIONS and POST, and i process the response. But, i'm trying to integrate this code with an existen application with uses jquery (i dont know if this is a problem), when the send(data) executes in this case, the browser (firefox) do the same, first do a OPTION request, but in this case dont receive the response of the server and puts this message in console:
[18:48:13.529] OPTIONS http://localhost:8111/ [undefined 31ms]
Undefined... the undefined is because dont receive the response, but the code is the same, i dont know why in this case the option dont receive the response, someone have an idea?
i debug my server app and the OPTIONS arrive ok to the server, but it seems like the browser dont wait to the response.
edit more later: ok i think that the problem is when i run with a simple html with a SCRIPT tag that invokes the method who do the request run ok, but in this app that dont receive the response, i have a form that do a onsubmit event, i think that the submit event returns very fast and the browser dont have time to get the OPTIONS request.
edit more later later: WTF, i resolve the problem make the POST request to sync:
this.xhr.open("POST", url, false);
The submit reponse very quickly and can't wait to the OPTION response of the browser, any idea to this?
Due to the same origin policy, you can't send cross origin post,
you can workaround it by include sites in iframes (if have access to the domain) original site contains iframe to the outer site, the inner direction is legal.