Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:09:03+00:00 2026-06-04T09:09:03+00:00

I am calling a server side function to return a json format string and

  • 0

I am calling a server side function to return a json format string and parse in client side using javascript and ajax. I got parse error at javascript. I think it is the backslash JavaScriptSerializer adds to serialize object. here is the response I see from firebug:
{“d”:”{\”Item\”:\”Testing\”}”} , i understand the backslash is to escape the double quote but how do i get json to fix this problem?? i spend 3 days and do all the search at google. It seems i am doing the same way as others. Thanks for help.

Server side Code:

[System.Web.Services.WebMethod]
public static string testmethod(string serial)
{ 
    ItemList itemlist = new ItemList();
    itemlist.Item = "Testing";     
    return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(itemlist);
}

[System.Runtime.Serialization.DataContract]
public class ItemList
{
    [System.Runtime.Serialization.DataMember]
    public string Item { get; set; }
}

Client Side Javascript with ajax:

function PassParemeterToAspxUsingJquery(serial)
{               
    var sn = "test";//serial;
    $.ajax({
    type: "POST",
    url: "test.aspx/testmethod",
    contentType: "application/json; charset=utf-8",
    data: "{serial:'" + sn+"'}" ,
    dataType: "json",
    success: function(msg) {           
       alert(msg.d);             
    },
    error: function(jqXHR, textStatus, errorThrown){
       alert("The following error occured: "+ textStatus, errorThrown);
       alert(jqXHR.responseText);
    }
    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:09:04+00:00Added an answer on June 4, 2026 at 9:09 am

    The WebMethod won’t embed the value as part of the JSON text. If you want it serialized as a JSON Object rather than a JSON String, you have to return an Object rather than a String:

    [System.Web.Services.WebMethod]
    public static object testmethod(string serial)
    {
        ItemList itemlist = new ItemList();
        itemlist.Item = "Testing";
        return itemList;
    }
    

    Though, this may require .NET 3.5 and a ScriptMethodAttribute:

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static object testmethod(string serial)
    { ... }
    

    Then just:

    success: function(msg) {
       alert(msg.d.Item);
    }
    

    Alternatively, you should be able to work with it as is by parsing msg.d:

    success: function(msg) {
        var data = $.parseJSON(msg.d);
    
        alert(data.Item);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've came into a need of calling a server-side function from a javscript function.
I am validating a zip code using Javascript that is generated server-side, and injected
this way i am calling my server side code....my code as follows. $(function ()
I am using node.js and express, and I am calling server-side functions and syncing
We are getting the error below calling c:\windows\syswow64\regsvr32.exe on Windows Server 2008 R2 x64.
So I am coding this client/server program. This code is from the client side.
When calling ASPxClientComboBox.AddItem() I get an error in the _aspxRemoveAttribute function, that obj is
I'm calling a server method from javascript. I've tested the server method and it
I wrote a server-client app in javascript/HTML5 its supposed to allow clients to communicate/play
I'm calling a classic .asp page from jquery to return a list (using JSONP).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.