hi here i attached the coding that from javascript using ajax get a datas from serverside
in that coding have ajaxsample.aspx file
it have 3 button
two button using webservice and one using .ashx file for handle data
the web service return xmldata as a string .
the same data from .ashx file working fine
but from webservice not working
please check and tell to me thanks
Loading

Anand UchagawkarPosted Sep 20, 2011, 8:35 AM
You haven't specified any error information so I can't figure out the exact problem. But from your code it seems that you need to call a WebMethod which will call a small functionality which can be attained by PageMethods concept which is very simple while implementation and also you need have carry additional .js files.
Here is the explanation of the implementation for the same:-
1. Add scriptmanager object to your .aspx page and EnablePageMethods attribute to true,
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">asp:ScriptManager>
2. Add a webmethod in your code behind file,
[System.Web.Services.WebMethod]
public static string GetMyContent()
{
//here add your logic to get your data
//i'm just returning the current date time string for simulation
return DateTime.Now.ToString();
}
4. Now you add the following script in your .aspx page
Here call CallForData() from any event from on which you want to retrive data.
In CallForData() calls PageMethods.GetMyContent, GetMyContent is the WebMethod which we have defined in the code begind page. Now the browser will call GetMyContent asynchronously so we specify the method name(OnGetMyContentComplete) which will get called once the .Net completes the request and gets result.
I think this will suffice your purpose, if not then let me know the error in your approach.
3. Note that for adding WebMethod you will have to add reference to System.Web.Services.dll