How to stop loading of iframe when the response for first request come.i have include this but this will load complete url which i don't want.i only want to set cookies from first request response
This is cross domain request
i have tried JSON get request but it is not setting cookies in my browser whihc i can use in next request.
please help us
this can be done by the window.stop():
try
window.frames[0].stop()
Related
There is a custom response header that I want to check and use that come from the initial page load request (the request browser send when we type in the url).
Is there a way for me to access that header as a script that sits on the page WITHOUT making another request?
Thanks
Problem:
I need to send a request from javascript to the server, containing a set header, that will reload the entire browser window on response.
jQuery ajax it seems does not fully load the browser window and can only re-target the document.
Essentially I'd like to do a window.location.reload(true) whilst also setting a request header.
You can't specify custom HTTP headers other then when using XMLHttpRequest.
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.
I'm working on an ad platform. When someone clicks on an image, I want to send a request back to my server to log this action. I have a pre-generated url for this. If I send a request to this url, it will log the data.
My issue is that the log url is on my domain, whereas the javascript is being executed in a client's domain. Without modifying the logging php script (to add something like Access-Control-Allow-Origin: *), is there a way to send this request to the new domain?
Since I'm only logging data, the server only sends back the text "OK" (which is information I don't need).
You should be able to send Ajax HTTP requests to any domain. I don't see what the problem is... It's the response that is restricted with the Same Origin Policy, not the request itself. You cannot access the response of the PHP script if the domains don't match, but the server will process the request normally, even if it's from a different domain.
This is a hack but it's commonly used. On click append an image to the DOM with the src set to the logging URL. To be friendly, have the output from the logging URL be a 1x1 pixel image. You'll have to pass the parameters via a GET string but it will work.
Create any dynamic DOM element with source on your domain (image or iframe), append a logging data to a request.
var logData = function(data){
if(data === undefined){
return;
}
var img=document.createElement("img");
img.setAttribute('src', 'http://another.domain?'+data);
img.setAttribute('height', '1px');
img.setAttribute('width', '1px');
document.body.appendChild(img);}
Your log requests will now appear in IIS logs
Cross-domain script restrictions are enforced at the browser level as a security precaution, so there is not a simple code fix to work around them. However, you can look at JSONP (JSON with padding) as a starting point.
You could create a hidden iframe with the src attribute set to the logging URL. This is at least as ugly as the image approach listed above.