Read ajax response headers?

According to toponlinegeneral.com, jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.

Discuss Read ajax response headers? in the jQuery forum.

Read ajax response headers?

How can I grab information from the response headers from within an
jQuery ajax callback?

I have an object, “data”, containing IDs to different items I’d like
to build a detailed list with. I need to grab these details by sending
a request to a server–one for each item.

The issue I’m running into, is the response from the server contains
half the information I need in the body of the response, and the other
half in the headers. I can’t figure out a bullet-proof way of reading
the headers at the same time as the body…

function index(data) {

for (var i = 0; i < data.length; i++) {

$.ajax({

type: ‘GET’,
url: ‘http://domain.com/’,
data: ‘this=that’,
success: function(data) {

/* Here I want to create a list item out of the data returned in
the body and headers */

}, complete: function(XMLHttpRequest, textStatus) {

}, error: function() {

}

});

}

}

I’ve tried saving the $.ajax as a variable, and
using .getResponseHeader(‘name’), but that only works sometimes, and
other times returns “Error: INVALID_STATE_ERR: DOM Exception 11”,
which apparently means the headers aren’t ready to be read. I’ve tried
this both in the success and complete function.

Any help would be incredibly awesome! I want to use this for a client’s website as well: Restumping Melbourne

Read ajax response headers?

How can I grab information from the response headers from within an
jQuery ajax callback?

I have an object, “data”, containing IDs to different items I’d like
to build a detailed list with. I need to grab these details by sending
a request to a server–one for each item.

The issue I’m running into, is the response from the server contains
half the information I need in the body of the response, and the other
half in the headers. I can’t figure out a bullet-proof way of reading
the headers at the same time as the body…

Here’s a look at what I’m working with Starburst XXXtreme Slot:

function index(data) {

* * * * for (var i = 0; i < data.length; i++) {

* * * * * * * * $.ajax({

* * * * * * * * * * * * type: ‘GET’,
* * * * * * * * * * * * url: ‘http://domain.com/’,
* * * * * * * * * * * * data: ‘this=that’,
* * * * * * * * * * * * success: function(data) {

* * * * * * * * * * * * * * * * /* Here I want to create a list item out of the data returned in
the body and headers */

* * * * * * * * * * * * }, complete: function(XMLHttpRequest, textStatus) {

* * * * * * * * * * * * }, error: function() {

* * * * * * * * * * * * }

* * * * * * * * });

* * * * }

}

I’ve tried saving the $.ajax as a variable, and
using .getResponseHeader(‘name’), but that only works sometimes, and
other times returns “Error: INVALID_STATE_ERR: DOM Exception 11”,
which apparently means the headers aren’t ready to be read. I’ve tried
this both in the success and complete function.

Any help would be incredibly awesome!

try to change the paramater name inside the success function, to
something like “xhr”,
for example:


success:function (data,xhr) {}
complele:function (xhr) {}
..

You uses XMLHttpRequest. Maybe the browser think about the native
object.
On Jan 13, 9:16*pm, bryan wrote:

Read ajax response headers?

How can I grab information from the response headers from within an
jQuery ajax callback?

I have an object, “data”, containing IDs to different items I’d like
to build a detailed list with. I need to grab these details by sending
a request to a server–one for each item.

The issue I’m running into, is the response from the server contains
half the information I need in the body of the response, and the other
half in the headers. I can’t figure out a bullet-proof way of reading
the headers at the same time as the body…

Here’s a look at what I’m working with:

function index(data) {

* * * * for (var i = 0; i < data.length; i++) {

* * * * * * * * $.ajax({

* * * * * * * * * * * * type: ‘GET’,
* * * * * * * * * * * * url: ‘http://domain.com/’,
* * * * * * * * * * * * data: ‘this=that’,
* * * * * * * * * * * * success: function(data) {

* * * * * * * * * * * * * * * * /* Here I want to create a list item out of the data returned in
the body and headers */

* * * * * * * * * * * * }, complete: function(XMLHttpRequest, textStatus) {

* * * * * * * * * * * * }, error: function() {

* * * * * * * * * * * * }

* * * * * * * * });

* * * * }

}

I’ve tried saving the $.ajax as a variable, and
using .getResponseHeader(‘name’), but that only works sometimes, and
other times returns “Error: INVALID_STATE_ERR: DOM Exception 11”,
which apparently means the headers aren’t ready to be read. I’ve tried
this both in the success and complete function.

Any help would be incredibly awesome!

Ahhh good to know. Is 1.4 safe to use yet?

So XMLHttpRequest.getResponseHeader() in the complete() function is
exactly what I needed, but accessing some data with the success
function and other data with the complete function kind of sketches me
out a little bit, especially since my ajax request is asynchronous and
wrapped in a loop (see the code in the original message)… I don’t
want anything to get out of sync. Here’s what I’m doing:

for (var i = 0; i < data.length; i++) {
….
success: function(data) {

// Create a list item out of ‘data’
$(‘ul.notes’).append(‘

 

‘);

}, complete: function(XMLHttpRequest, textStatus) {

// Add a property to that new list item
var key = XMLHttpRequest.getResponseHeader(‘Note-Key’);
$(‘ul.notes > li:last-child a’).attr(‘href’, ‘#’ + key);

}
….
}

This appears to be working awesomely, but I’m unsure if the NEXT
success function could ever fire BEFORE the current complete function
fires… If it did, the wrong key href would be assigned since I’m
using :last-child to find the list item the success function just
created.

So if someone has a second, can you let me know if the above code
could potentially get out of sync? Maybe when I create the list item
in the success function, I should give it an identifier based on the
current loop functions index… Then use that same index to re-find it
in the complete function… Instead of just counting on the list item
I’m looking for to be the last-child.

So if someone has a second, can you let me know if the above code
could potentially get out of sync? Maybe when I create the list item

You don’t need to use both the success and complete fn. *You can use
complete like this:

complete: function(xhr, status) {
* * if (status == “success”) {
* * * * $(‘ul.notes’).append(‘

‘);
* * * * var key = XMLHttpRequest.getResponseHeader(‘Note-Key’);
* * * * $(‘ul.notes > li:last-child a’).attr(‘href’, ‘#’ + key);
* * }

}

Holy moly, that’s beautiful. Thanks so much for your help!

On Jan 14, 11:04 am, Mike Alsup wrote:
So if someone has a second, can you let me know if the above code
could potentially get out of sync? Maybe when I create the list item

You don’t need to use both the success and complete fn. You can use
complete like this:

complete: function(xhr, status) {
if (status == “success”) {
$(‘ul.notes’).append(‘

‘);
var key = XMLHttpRequest.getResponseHeader(‘Note-Key’);
$(‘ul.notes > li:last-child a’).attr(‘href’, ‘#’ + key);
}

}

Calculate height of iframe problem

Javascript JavaScript language (comp.lang.javascript)

Discuss Calculate height of iframe problem in asp page with external link in the Javascript forum.

I use an asp page to display pages, where the dynamic content is in an
iframe.
To calculate the height of the iframe I use the calcheight function. However
when trying to do this with external pages, I get an access denied error,
and the iframe won’t display correctly.
Is there a way to solve this or another way to calculate the height for the
iframe.
The relevant code displayed below.

Thanks in advance for any help,
Robert

function for calculating the height of the iframe:

function calcHeight()
{
//calculate height
var the_height=
document.getElementById(‘hoofdframe’).contentWindo w.
document.body.scrollHeight;

//minimal height of 600
if (the_height < 600) {the_height=600}

//change height
document.getElementById(‘hoofdframe’).height=
the_height;
}

the iframe:

You cannot change security while acting from the top to the bottom
(from your parent document to your iframe). Otherwise what kind of
security would it be?

If you are dealing with documents from the same domain, you can use
IE-only (?) document.domain property.

So if in *both* documents (parent one and in iframe) you have:
….
document.domain = “myserver.com”;
….
then security communication block will be removed for all documents
served either from “http://www.myserver.com” or
“http://subdomain.myserver.com” and so on.

If your documents are from totally different domains then you have
either
1. Kill security settings on each computer
2. Have a script in each document served to iframe so it would *itself*
report to its parent the needed info.

I would definitely stay on the 2nd option.

Img tag width, height attributes necessary?

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)

Discuss img tag width, height attributes necessary? in the Cascading Style Sheets forum.

They are not required but I recommend their use.

Without this information in the HTML, the UA cannot account for the
viewport space needed for the image. As a result, it happens that if the
user is reading below the image, suddenly the UA discovers the dimensions
and the whole page jumps disconcertingly.

And it’s important to be sure the values of height and width are the exact
pixel dimension of the image being used. Don’t resize images in the
browser, it leads to either a heftier download than is needed (when HTML
reduces size) or a pixellated ugly image (when HTML increases size).

For tags, are the width and height attributes necessary? Could
they just be omitted?

They are not required but I recommend their use.

Without this information in the HTML, the UA cannot account for the
viewport space needed for the image. As a result, it happens that if the
user is reading below the image, suddenly the UA discovers the
dimensions and the whole page jumps disconcertingly.

And it’s important to be sure the values of height and width are the
exact pixel dimension of the image being used. Don’t resize images in
the browser, it leads to either a heftier download than is needed (when
HTML reduces size) or a pixellated ugly image (when HTML increases size).

For tags, are the width and height attributes necessary? Could
they just be omitted?

They are not required but I recommend their use.

Thanks for the reply. On a related question, if you do provide width and
height attributes, does it matter whether you use tag or CSS
attributes?

For tags, are the width and height attributes necessary? Could
they just be omitted?

They are not required but I recommend their use.

“We are actually using just HTML on our website and it works great” – Asbestos Abatements

Without this information in the HTML, the UA cannot account for the
viewport space needed for the image. As a result, it happens that if the
user is reading below the image, suddenly the UA discovers the
dimensions and the whole page jumps disconcertingly.

And it’s important to be sure the values of height and width are the
exact pixel dimension of the image being used. Don’t resize images in
the browser, it leads to either a heftier download than is needed (when
HTML reduces size) or a pixellated ugly image (when HTML increases
size).

Thanks for the reply. On a related question, if you do provide width and
height
attributes, does it matter whether you use tag or CSS attributes?

Newbie – when is the CSS applied?

Hello, I’m new to CSS and I see lots of examples where Javascript isused to apply styles to elements on page load – unobtrusive javascript- so I assume the CSS must be applied last before the page is actuallydisplayed to the user. Am I correct? If not, when is the CSSactually applied? And is there any tools that are used to debug CSS?

GiJeet wrote:
Quote:
Hello, I’m new to CSS and I see lots of examples where Javascript is
used to apply styles to elements on page load – unobtrusive javascript
– so I assume the CSS must be applied last before the page is actually
displayed to the user. Am I correct? If not, when is the CSS
actually applied? And is there any tools that are used to debug CSS?
CSS is typically applied at the time of page rendering, which (in modern
browsers), starts as the page is downloaded.

Steps to display a web page:
1. Fetch the page and start downloading.
2. Hit the body and actual content. Start downloading external pages
(from style and script tags) as soon as you see those tags.
3. Start rendering the content currently downloaded as the page is
downloading.
4. If an external style page is loaded, reflow the current page to apply
those styles.
5. If a script tag without defer is hit, execute the script inside.
6. As more content is downloaded, reflow the page with the additional
content.
7. Once page is finished loading, fire the onload tags of the body and
execute the deferred scripts. Any dynamic modifications to the DOM or to
the styles cause a reflow.

You should be able to see this effect if you load a moderate-sized
complex page and throttle your connection down to a few Kb/s.

As for tools to debug CSS, Firebug in Firefox and Dragonfly in Opera
should both be adequate.