This is a migrated thread and some comments may be shown as answers.

Is it possible to do a simple javascript call to the server?

3 Answers 139 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
LeBear
Top achievements
Rank 1
LeBear asked on 11 Mar 2008, 11:02 AM
I would like to be able to perform a simple call to the server just to get some information.  The simplest example of this is that I would like to issue a call from the client like this:

myBoolVar = serverIsThereNewDataForMe(MyID);

or

myStringVar = serverWhatIsYouFavoriteColor();

I specifically want to be able to ask the server for some simple data without having to incur the overhead of the normal Ajax call where the entire page script is run.  The reason for this is I might be making a call back to the server every second or two and I'd like to optimize this to be as simple as possible with as little network traffic as possible.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 14 Mar 2008, 03:14 PM
Hello Barry,

Please refer to the following online resource . There you will find information for the RadAjax Client-Side API which should help you achieve the functionality you are searching for.

Best regards,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
LeBear
Top achievements
Rank 1
answered on 14 Mar 2008, 05:19 PM
I don't see a direct way to do what I want to do.

Let's say that I have a chat window and I want the chat output control to be updated with new posts as they come in, but I want to reduce network traffic as much as possible.

I have a scenario where I would like to have the page (client-side) call a Web Service that asks if there are more posts available.  The Web Service would return a boolean indicating in there were more posts.  Then the client would make the call to update the chat output only when it was determined there were more posts. 

Here's a simple look of what I want on the client.

[Javascript]
function getMorePosts(){
    var moreposts;
    moreposts = AjaxManager(WebServiceURL, IdOfLastKnownPost);
    if (moreposts){
        AjaxManager.AjaxRequestWithTarget(...);
    }
}
[/Javascript]

The call to the web service would NOT be a call to the current page, but rather a simple web service that just looks to see if there are more posts after the last known post ID that was passed in.  If there are more, it will return a true, and if not, it will return a false.

With this type of call, you would realize much less processing and network overhead by first checking with the server if there were more chat posts, and if there were, you would then make the actual call to update the chat activity control.

There are other scenarios I would like to do this as well.  For example, a web page could check every now and again to see if a message were created for the user, and display a You Have Mail icon.

Thanks.
0
Maria Ilieva
Telerik team
answered on 18 Mar 2008, 02:00 PM
Hi Barry,

Thank you for the detailed explanation.

In order to achieve the required functionality, you could use the RadAjaxSeviceManager control. Please review the following help topic, which describes the control and its functionality. Also you could refer to these online examples, showing some implementation of the ServiceManager control.
Please note that, if you decide to use the RadAjaxServiceManager and need to initiate synchronous Service Call,  you should set  the control  "PerformAsyncronousRequests" property to "false", as it is set to "true" by default.

Let us know if the provided information is helpful.

Best wishes,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Ajax
Asked by
LeBear
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
LeBear
Top achievements
Rank 1
Share this question
or