Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. a javascipt qustion

a javascipt qustion

Scheduled Pinned Locked Moved Web Development
questionjavascriptsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xiaoming Qian
    wrote on last edited by
    #1

    Hi everybody,I'm a new comer to javascript.I have a question.English is not my mother language.I'll try my best to explain clearly what I mean. Look at the following code: var CallComplete; function MyFunction() { CallComplete = false; //Make asynchronous call of a server method SeverMethod(CallBack); //wating for CallComplete //but it takes such a long time to waiting the call complete while (!CallComplete) { } return something; } function CallBack(response) { ... CallComplete = true; } The ServerMethod is quite simple,and it will return immediately if I remove the while loop from the above code.But MyFuntion must wait for the severmethod's data to return values. Is there any better way waiting for the asynchronous call complete? Any idea will be appropriate.

    G 1 Reply Last reply
    0
    • X Xiaoming Qian

      Hi everybody,I'm a new comer to javascript.I have a question.English is not my mother language.I'll try my best to explain clearly what I mean. Look at the following code: var CallComplete; function MyFunction() { CallComplete = false; //Make asynchronous call of a server method SeverMethod(CallBack); //wating for CallComplete //but it takes such a long time to waiting the call complete while (!CallComplete) { } return something; } function CallBack(response) { ... CallComplete = true; } The ServerMethod is quite simple,and it will return immediately if I remove the while loop from the above code.But MyFuntion must wait for the severmethod's data to return values. Is there any better way waiting for the asynchronous call complete? Any idea will be appropriate.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      The reason for having a callback is that you don't need to wait for the call to complete. When it completes the callback method is executed. Whatever you need to do after the call completes, you can put in the callback method. --- b { font-weight: normal; }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups