I have a simple function in my web service.
[WebMethod]
public string TryWB()
{
string sMsg = "try";
return sMsg;
}
and I am calling it from my aspx page. At the top I have tried
[ScriptMethod( ResponseFormat= ResponseFormat.Json)]
(or .xml or even httpget) and in the function also I have tried serialising it with
sMsg = (new JavaScriptSerializer()).Serialize(sMsg);
or even made custom object just to wrap message and even tried
JsonConvert.SerializeObject(cm,Newtonsoft.Json.Formatting.Indented);
From my aspx pages all combinations of text, xml, json made
$.ajax({
URL: 'FLMSWebService/Login.asmx/TryWB',
method:"POST", (get also tried)
contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (data) {
alert('success');
alert(JSON.stringify(data));
},
error: function (jqXHR, exception) {
alert(jqXHR.responseText);
}
});
I've tried: contentType: json, xml
and I've tried datatype : xml , json
I tried in web.config also
<system.webserver>
<modules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
and
<system.web.extensions>
<scripting>
<webservices>
<authenticationService enabled="true" />
This is all I got from my 2 day search on net...but main point if I have
dataType: "text",
It's a success and full page returned as data in every other datatype or contenttype I get error and the full page is shown in
alert(jqXHR.responseText);
in the error callback. I am stuck!! please help
What I have tried:
in webservice method..
tried returning a simple string as it is or used JavaScriptSerializer
or xml format (created a simple string in xml format)
or object (in this case jsonconvert.serialize)
also used scriptmethod with all responseformats, even httpget tried
web.config file - ScriptModule added and webextensions added
in scriptmanager EnablePageMethods="true" added
and in .ajax(
datatype all tried json xml text (only ttext gives success but data is full page)
contentType: json, xml - tried