strange behavior with javascript Client Object Model
-
2012年8月1日 下午 09:20
We are doing some scripting, where the user clicks a button which examines all the items in a list and then adds some new list entries. We see really wierd behavior with the client object model sometimes. right now, clicking the button calls a method that submits an async request to read all the list entries. The OnSuccess method then examines those entries and calls another method to insert new items.
What we are seeing is that if you click the button once, we get a debug alert showing code entered the code prior to reading all entries, but we never get an alert inside the "onSuccess" method. If we then click the button again, we get the first debug alert, and then the second alert too (from inside the onSuccess method). WHY? Why does the second click seem to return a result whereas the first click doesn't? I brought up fiddler, and it looks like a request is sent to the server and received by the client on both clicks - but only the second one seems to kick off the onSuccess method.
Thanks.
所有回覆
-
2012年8月3日 上午 10:11版主
Thanks for sharing the post.
I’m trying involve someone familiar with this topic to further look at this issue.
Thanks,
Qiao Wei
TechNet Community Support
-
2012年8月3日 下午 02:02
The developer on my team working on this got it figured out - the problem we were experiencing this time was caused by a failing call to web.get_currentUser() - we didn't realize that was an async call also - and the code was failing the first time it ran - I guess the second time we called the method it was batched in with the other async calls we were making.
it just seems like we often have odd behavior using the javascript client object model - things that don't always run when we expect them to. Maybe it is more issues like this, where we just miss some simple async quirks. it gets frustrating!
Thanks.
- 已標示為解答 Qiao WeiMicrosoft Contingent Staff, Moderator 2012年8月12日 上午 11:20
-
2012年8月3日 下午 09:15
Hi JJ,
Greetings! Thanks for the post.
I see that you have figured out the real reason behind the OnSuccess method being called only on second button click.
Let me know if you need any information regarding the same.
================================================================================
Please remember to click 'Mark as Answer' on the post that helps you or click 'Unmark as Answer' if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Thanks,
Bharat Rathod,
Microsoft Online Community Support

