Use true Ajax from ajax

Make Script based web service which could be called by JavaScript

I remember the days when I need to call web service from JavaScript using some HTML component called webservice.htc. It was a pain to consume web service using that component as compare to current solution provided by Asp.net Ajax team of Microsoft. I must say, Hats off to Microsoft for making life easier of the developers of their technologies. Following are few factors for using “calling web service from JavaScript”.

When you need to:

  • Call web server and perform some operation on server like updating database or some File I/O operations or have to queue the requests and have less to do on client side like just need to show Operation completed or data based updated.
  • Send request to web server asynchronously and don’t want to put user on wait for completion of request
  • Perform operation on server side more efficiently as you wont follow page life cycle

When you don’t need to:

  • Initiate Page object and/or need to follow page life cycle
  • Post back page and Render page automatically
  • Send request to web server synchronously and put user on wait of completion of processing
  • Submit form
  • Use cache, session or need to access any asp.net intrinsic object

Aforementioned points tells simply, when to call web service from JavaScript and when not.

For more details and better understanding please visit following link http://worldofasp.net/tut/ajax_webservice/Ajax_enabled_web_service_237.aspx

Thanks

———————————————————————————————————————————————————————————-

XMLHTTPRequest

Normally, when you have to do some operation at server side, say some database oriented operation like any of well known CRUD (create, retrieve, update and delete) operations. You will submit whole form/page to server and get a whole new page from server to re paint on your browser. In very few, situations that are ok but mostly its not required at all.

Suppose, you have header image, left navigation bar, footer links like (contact us, about us, privacy policy…) and in middle of page some textboxes and one submit button.

You fill those textboxes and want to save given information in database and then clear the textboxes. Sounds good!

But what happen, when you click on submit button, all the contents on the web page will go to the server like header, footer, navigation bar and your textboxes. Purpose of submit button was to save information given in database then why header, navigation bar and footer being sending to server. I guess, it doesn’t make sense until they are needed to update.

So, if you want to send your specific controls data only to server and want to update those controls at browser side, then here comes “XMLHTTPRequest” object.

XMLHTTPRequest is JavaScript object which used to send request to server and receive response from server. Through XMLHTTPRequest, you can communicate with server synchronously and asynchronously as well. It depends upon your need of communication. If your next step(s) relying on server response then you need synchronous communication pattern but if don’t want to keep user on wait, don’t want to freeze User Interface (UI) at user side and can proceed without having result on next line of call then you can use asynchronous communication pattern.

For more details and better understanding please visit following link http://worldofasp.net/tut/XMLHTTPRequest/XMLHTTPRequest_236.aspx

Thanks

Kindly feedback🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s