Click here to Skip to main content
14,774,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am using Jquery Ajax to call my pagemethod in When I use
contentType: "application/json; charset=utf-8",
              dataType: "json",

jquery ajax gives me error and if I dont write content type and datatye then comple page html is shown in the respose. below is my jquery ajax and .cs code:

function CallAjax()

type: "POST",
url: "MyAdmin.aspx/GetLabelValue",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
error: function(msg) { alert('fail')}


and MyAdmin.aspx.cs :

  public static string GetLabelValue()
      return "hello";

Please guide me. Thanks !


1 solution

Well here's the syntax of the AJAX I'm using on one of my own pages, which works fine for me:

var xml;
var fetchError = false;

    type: "GET",
    contentType: "json",
    async: false,
    data: { someVar: 'some value' },
    url: "WebService.asmx/putStockplanFile",
    success: function (msg) {
        // store message returned by the request
        xml = msg;
    error: function (msg) {
        // set a flag to indicate request returned an error
        fetchError = true;

So why not give that a go first to see if it makes any difference.
Moykn 10-Apr-13 13:51pm
looks like this approach doesn't works in 2.0, what happens is the server always responding with the complete page, so when you specify a dataType="json" the response fails to be validated as a json object, it seems that he will need to create a webservice to handle such calls.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900