[Javascript] JSON element has no properties - how to validate?

David Lovering dlovering at gazos.com
Thu Nov 22 09:15:25 CST 2007


My guess is that the multiple triggers are being caused by a failure of the 
keyboard event handler, either in the browser or in the
system's window-manager.  I suspect this may hearken back to a buggy 
"auto-key-repeat" glitch in the OS, but of course that is pure speculation.

One way to (possibly) beat the problem is to assign a state-value to "foo" 
that remains null until such time as the function is invoked, and then 
change state upon first return from the AJAX handler.  Reset this flag only 
when the form or field is scrubbed, so that you won't get phantom triggers. 
If the flag is set when the function foo triggers, simply exit without 
further action.

The alternative strategy is to see if the false triggering occurs 
before/after the AJAX call, as you may be seeing a fast response on one 
event/call and some appreciable latency on the other.  Obviously, the 
pairing will only work as fast as the slowest part of the whole while the 
fast portion will fire off like a machine gun.

One of the headaches of using keyboard event handlers to deal with calls to 
AJAX is that each browser tends to handle onkeyup, onkeypress, onchange 
events differently - some are quite bizarre.

-- Dave Lovering

----- Original Message ----- 
From: "Michael Borchers" <list at tridemail.de>
To: "JavaScript List" <javascript at lists.evolt.org>
Sent: Thursday, November 22, 2007 2:40 AM
Subject: Re: [Javascript] JSON element has no properties - how to validate?


> ----- Original Message ----- 
> From: "Scott Reynen" <scott at randomchaos.com>
> To: "JavaScript List" <javascript at lists.evolt.org>
> Sent: Wednesday, November 21, 2007 3:27 PM
> Subject: Re: [Javascript] JSON element has no properties - how to 
> validate?
>
>
>> On Nov 21, 2007, at 1:20 AM, Michael Borchers wrote:
>>
>>> I get an httpRequest(myRequest.response) formatted by php into a
>>> JSON format, it looks like this:
>>>
>>> [{"price":42.4535153,"error":null}]
>>>
>>> I handle it this way so far:
>>>
>>> var transport            = eval(myRequest.response);
>>> var transportError     = transport[0].error;
>>> var transportPrice    = transport[0].price;
>>>
>>> Since "error" is empty (null) I get a warning: "transport has no
>>> properties"!
>>
>>
>> What makes you think error being empty is causing this warning?  It
>> certainly sounds like transport itself is empty.  I suggest you double
>> check that myRequest.response and transport actually contain what you
>> think they do.
>>
>> Peace,
>> Scott
>
> Hi Scott, I believe you are right. This is how my request works:
>
> I have an input field with a max size of 5 numbers. When exactely 5 
> numbers
> are entered a onkeyup="" function starts the request.
>
> No problem so far!
>
> But when somebody enters the numbers very fast, the request ist started up
> to 5 times at the same time.
> One of the responses is ok then, the other 4 fail and give me the error
> ""transport has no properties"!
>
> I will have to check if the response is correct anyway!
>
> But what makes "a fast entering of numbers" exactely start several 
> requests,
> allthough a validation script does not start a request until exactely 5
> numbers have been entered?!
>
> <input type="text" name="number" size="5" maxlength="5" onkeyup="foo">
>
> function foo(myValue) {
>    if(!isNaN(myValue) && myValue.length == 5) {
>         var url = '...';
>
>         myRequest   = new sack();
>         myRequest.requestFile = url;
>         myRequest.onCompletion = function() { myNextFunction() };
>         myRequest.runAJAX();
>    }
> }
>
> http://www.twilightuniverse.com/projects/sack/
>
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
> 





More information about the Javascript mailing list