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

Michael Borchers list at tridemail.de
Thu Nov 22 03:40:39 CST 2007


----- 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/




More information about the Javascript mailing list