John Wang wrote:
On 6/1/06, *John Wang* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Does anyone know what the max length for a header in IE is? When
my X-JSON value is 138 bytes, it works fine but when it's 1659 it
fails. Is this documented anywhere?
I put up a blog entry on this. For now I'm just going to put the JSON
string in the response body and eval it myself. Since the IE6 length
problem doesn't exist when the JSON string is in the response body and
other AJAX libraries expect the JSON object there, does it make sense
for prototype to move that way as well?
http://dev411.blogspot.com/2006/06/prototype-x-json-fails-on-long-value.html
Hi all,
I find I take a different view on this. I just recently took the time to
understand Prototypes Ajax system by using it to implement a small
project I had.
I fond the X-JSON header when I was looking to solve a problem that was
coming up for me. I was looking for a way to determine if an Ajax call
was successful. I was facing having to parse the response body, when I
found the header.
My take, and the way I will be using it, is that the header is for the
Meta Data *about* the Ajax transaction, and the response body is for the
actual data that is the point of the transaction. Thus I use the header
for success/failure info and error messages, and the body may or may not
contain any data.
Here is a sample from that app, which allows the user to add anew event
to a calendar. The server code, in response.php, is written in PHP. The
function addEvent() simply formats the html fragment for a new event.
case 'addEvent':
$row = addEvent();
if($row < 0)
{
header('X-JSON: {"Result":"Failed", "Message":"Could not
successfully run query."}');
}
else
{
header('X-JSON: {"Result":"Ok"}');
echo formatEvent($row);
}
exit;
break;
The Javascript code makes the Ajax call when the user clicks the Add button.
function addevent(targ)
{
// alert("Adding...");
new Ajax.Request( responder, {
parameters: "function=addEvent&data=" + targ,
onComplete: completeAdd
});
}
function completeAdd(reply)
{
json = reply.getResponseHeader('X-JSON').parseJSON();
if(json)
{
if(json.Result == "Ok")
{
new Insertion.Bottom('schedulelist', reply.responseText);
}
else
{
alert("Error: " + json.Message);
}
}
else
{
alert("Error: Contact with the server failed. Please Refresh
the page.");
}
}
I hope this adds a different perspective on this X-JSON header issue.
--Will Merrell
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs