Monika Bhardwaj

Monika Bhardwaj

  • NA
  • 34
  • 636

Ajax Call - simple web service method returns entire page

Mar 2 2018 8:05 PM
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);
}});
contentType: json, xml tried
datatype : xml , json 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"/>
</modules>
and
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" />
</webServices>
</scripting>
</system.web.extensions>
this is all i got from my 2 day search on net...but main point if i have
dataType: "text",
its 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

Answers (1)