Sent from my iPhone
Mmm, actually it is necessary unless there is a global handler active.
-- Sandy
C-L is not required.
I would hazard a guess that the problem has to do with content
compression, i.e. you set the plaintext length and you have something
subsequently gzipping the content but not updating the header,
something like that. So you end up with a mismatch. Without the
header, there's nothing to mismatch.
-- Sandy
I would not be specifying length by hands unless connection is timed
out while sending back a very long string. Although if this is the
case I'd rather think about design than tweak headers. Usually 30
seconds is more than enough (especially with modern connection speeds)
to request and receive response from server using Asynchronous
connection with JSON, XML, HTML or whatever. I personally prefer to
stick with JSON because it is well packed data that can be expanded
into HTML, XML in Browser with Mootools.
Do you really have to transmit such a long list of strings?
Jan
--
Jan - MooTools comitter
twitter/blog: http://kassens.net
1. use header(...) in PHP before any other functions (another example
is session_start() ). Otherwise functions especially DB ones may
produce error or warning messages that would be output before header
and thus break data transmission. Suppress warnings and error messages
in PHP with @ prefix in functions if header can not be called before,
for example:
$output = @json_encode( $outputArr);
2. Why do you care about page timeout? Is user connected via modem
with old connection speed of several kBs? What's the point? Do not
transmit large data. Break it into smaller logical pieces and make
several requests instead. Example:
- Log. Instead of transmitting the whole DB return by server entries
headers and let each entry to download body with its own request
because body may be a long text.
- Users list: the same idea as with Log: return basic data, say users
list with IDs only and then request each user separately.
Such approach will work faster then requesting one huge block of data
and then waiting for 5 minutes to get it back from server. After all
it requires less neat programming.
3. I also write pages using Mootools Requests and honestly never had
problems with C-L. The whole idea of Requests ( and AJAX at first
place) is that Browser updates SMALL parts of pages otherwise refresh
page. It means: Do not send long contents. There are always at least 2
different ways to implement the same concept in programming. Redesign
your code and you'll see that setting headers explicitly is not
necessary unless extremely specific case like generation of image on
fly.
By the way nice way to suppress caching by browser is to add time to
URL, e.g.:
new Request.JSON({
url: './pages/get/data.php?t=' + $time(),
...
}).send();
$time() has precision of milliseconds and there is no way your code is
going to make two request at exactly the same time moment.
AJAX, Mootools Requests and Asynchronous requests are NOT made or
designed for Images. They are made for HTML, XML, JSON, HTML and TEXT
reply but NOT images! Let browser to handle itself image upload and
add slot for event onLoad for that image that is generated dynamically
on server. So, do something in code like:
var _newImage = new Element( 'img', { url: './images/dynamic_photo.php?
t=' + $time() + '¶ms', events: { 'load': _onLoadImage } });
I am sorry for possible incorrect syntax in Image element. It only
intended to give an idea.
So, once image is downloaded by browser then you'll get _onLoadImage
function called.
Browser automatically loads images and waits until it is completely
transmitted. But in given case you may need to specify contents length
(not sure about it). Definitely you need to define TYPE in header.
Anyway I do not understand why Request is needed for this? By the way,
Safari 4 has extremely friendly developer tools that you may wish to
use to see all requests and responses to/from server.