Google chrome extension read on page sequest - ajax

I have a page with a middle ajax frame. This frame does a lot of requests. Last 2 requests are always this:
Last-1) Request GET page with url www.mysite.com/page1.php and the page response have always a text with "true" or "false".
Last) POST request with url www.mysecondsite.com/page2.php and the page response is empty.
I need to write an extension that reads if last-1 request is True or False and do something when last request is finish.... I tried use chrome.webRequest library but it didn't work...
How can I do this?
Edit: I know this, but I don't want script to do the request... Request are done by page because site need do some operation. I only need an extension to read this request.... but don't do it!
Edit2: I don't want to modify code on page.... I want only to check the response of this page (tab) at some AJAX request. I cant do ajax request or modify script.. only read response, is this possible?

You could make request to other sites using XMLHttpRequest object.
Chrome extension tutorial

Depending on how complex it is you could try replacing the function on the page that does the request with a copy that does the same but also sends the info to your extension.
Its hard to give advise without seeing the page in question.

Related

Tomcat's form based authentication with ajax app

I use tomcat's form based authentication on a webapp which use most of the time ajax call.
The configuration of the realm is pretty well documented, and it's working.
My problem begin when the user's session is ended, for any reason.
The subsequent ajax call will have a 200 ok response, with the content being the login page.
I'm looking for a way to change the beavaior of tomcat, like sending a 401 instead of hiding the content, forcing a client redirect, or any other solution that let the JS script know that the session is over and authentication is required once again.
After reading this http://www.htmlcodetutorial.com/document/index_tagsupp_13.html, I tried to add some custom header with http-equiv meta tag in my html login page.
But it doesn't work as expected. It seams that tomcat doesn't read static content in order to add headers.
I should also mention this post:
http://blog.pengoworks.com/index.cfm/2007/10/9/Expiring-Session-via-AJAX-using-HTTP-Response-Headers
What i end up doing is, on the js side, scan start of every response using a short regexp like this:
/^<!DOCTYPE html>/.test(responseBody)
It works, but take extra time for every request.
It only work because i know that i never use html as answer from the server.

how to make a request like ajax

According to this website: I am trying to make a request, send data, and hope to get the result like json format, but not have to be.
In the sandbox page, I've checked the javascript, (I am using Chrome browser, you can go to "resources" -> Frame folder -> sandbox.ala.org.au), it uses AJAX to send and get data.
For example, there is a function (parseColumns), which is using ajax for sending data and getting result.
Is there any other way instead of ajax that could make a request to the server and get the result data? Because I am trying to create an application work similar with the sandbox.
One alternative is to make regular http requests. The problem with this approach is that you have to decipher the data format for input and output.
You can see all the request/response traffic in details, from and to your browser, using firebug (https://getfirebug.com/) and enabling the "net" tab
when you mouse over the "POST" line in the URL column, it shows you the complete URL. Click on the (+) to expand the request item to see details on the request.

Why URL Data does not shows for GET method in ajax?

As we know, GET method sends data via URL. We can use both GET and POST method in ajax. My question is, why can't we see the data in URL when we use ajax with a GET method?
AJAX call is not visible through url.
Try to use firebug extension of firefox.
In firebug, you will find all request in console.
When you fire off your ajax request like this:
The Chrome network tab will show new line for this transaction:
If you click on it, it will show you all the details:
If you'd like more information on constructing your own querystrings, look at this other question: How to build query string with Javascript

Effective way to avoid caching during Jquery Get (AJAX)

I am experiencing random occurrences of caching of Ajax requests created through Jquery's get.
The Jquery gets are done in the most straight forward conventional way (route + params + callback)
I am already using
$.ajaxSetup({cache:false});
But it doesn't seem to always work. I get how ajaxSetup no cache works, and I see the added random parameter being added to my request url.
My current browser is IE 8.0
Does anyone know of another solution besides the ajaxSetup way...
The browser itself is simply not allowed/able to cache requests with distinct parameters, as added by {cache:false}.
It sounds like the caching is happening somewhere else in your chain, possibly in your web server/app.
Use firebug's net tab to check exactly what is being requested by the browser, and what the URLs are exactly, then take it from there.
It turns out I was wrong about my assumption about caching of ajax requests.
The real issue was caching of subsequent redirect to action requests that took place on the server (in response to the original ajax call).
The solution ended up being the following attribute.
[OutputCache(Location = OutputCacheLocation.None)]
It can be either applied at the controller level or the action level.

Can headers be sent in an AJAX request?

Can I call the server to set a new cookie with an AJAX request (that is, after the page has already loaded)?
For example, when a visitor hits a link, ajax would open a php file that sets a new cookie like this:
setcookie('cookiename', 'true', time()+3000, "/",'...');
But this is done after the html (the page containing the actual <a> tag pressed) was rendered. Is it nevertheless ok to set cookies in ajax? (maybe because the php file loaded is separate from the original html page).
You can have the server's response set a cookie, certainly. Remember that cookies are an HTTP thing, not an HTML thing; the fact that your original HTML file is already on the browser is irrelevant. Your ajax request is a separate HTTP request to the server, which (hopefully!) generates an HTTP response back to the browser; and that response can include a new Set-Cookie header.
I'm not a PHP person, you'll need to check that there are limitations in the PHP mechanism you're using for setting the cookie (I can't imagine there are). But fundamentally, no, there's no problem doing this. I've done it with both JSPs and classic ASP.
I've set cookies in the response to AJAX requests on my site and I haven't had any problems with it yet. (Although I haven't looked for problems.) It could be that some browsers don't set cookies when receiving them in an XmlHttpRequest but so far I've seen it work in IE, Chrome and Firefox.
Why not use javascript to edit cookies? Return the content of the cookie in JSON format and use javascript to store the values.

Resources