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 7716045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:32:18+00:00 2026-06-01T02:32:18+00:00

Not sure what I’m doing wrong but I can’t get my JQuery AJAX call

  • 0

Not sure what I’m doing wrong but I can’t get my JQuery AJAX call to pass the variable properly. It recieves it just fine. I’m probably overlooking something minor. Thanks.

(Also, is there any way to pass data this way without using a [WebMethod] or via the URL?)

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script src="Scripts/jquery-1.7.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function() {   
            $('#button').click(function(){
            var json_obj = "{'" + $('#t1').val() + "' : '" + $('#p1').val() + "', '" + $('#t2').val() + "' : '" + $('#p2').val() + "'}";

                $.ajax({
                    type: "POST",
                    url: 'Default.aspx/test',
                    contentType: 'application/json; charset=utf-8',
                    data: "thisisatest",//json_obj,
                    dataType: 'json',
                    success: function(msg) {
                    //$('#result').html(msg.d);
                        alert(msg.d)
                    },
                    error: function(msg) {
                    //$('#result').html(msg.d);
                        alert(msg.d + " err")
                    }
                });
            });
        });
    </script>
</head>
<body>
    <div>
        Type: 1: <input type="text" id="t1" />
        Property 1: <input type="text" id="p1" />
        <br /><br />
        Type 2: <input type="text" id="t2" />
        Property 2: <input type="text" id="p2" />
        <input type="button" value="Add object!" id="button" />
        <br /><br />
        <div id="result"></div>
    </div>
</body>
</html>

Code Behind

    [WebMethod]
    public string test(string json)
    { 
        return json;
    }
  • 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-01T02:32:20+00:00Added an answer on June 1, 2026 at 2:32 am

    Here’s a full example I wrote for you to illustrate the concept:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Web.Services" %>
    <script type="text/C#" runat="server">
    
        public class MyModel
        {
            public string T1 { get; set; }
            public string P1 { get; set; }
            public string T2 { get; set; }
            public string P2 { get; set; }
        }
    
        [WebMethod]
        public static string Test(MyModel obj)
        {
            return "Hello from test";
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        Type: 1: <input type="text" id="t1" />
        Property 1: <input type="text" id="p1" />
        <br /><br />
        Type 2: <input type="text" id="t2" />
        Property 2: <input type="text" id="p2" />
        <input type="button" value="Add object!" id="button" />
        <br /><br />
        <div id="result"></div>
    
        <script src="scripts/jquery-1.4.1.js" type="text/javascript"></script>
        <script type="text/javascript">
            $('#button').click(function () {
                var data = JSON.stringify({
                    obj: {
                        t1: $('#t1').val(),
                        p1: $('#p1').val(),
                        t2: $('#t2').val(),
                        p2: $('#p2').val()
                    }
                });
                $.ajax({
                    url: 'default.aspx/test',
                    type: 'POST',
                    contentType: 'application/json',
                    data: data,
                    success: function(result) {
                        $('#result').html(result.d);
                    }
                });
                return false;
            });
        </script>
    </body>
    </html>
    

    I have mixed here the code behind and the markup in the same Default.aspx file but obviously you could have them separate if you prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure what I'm doing wrong, but here is the code 1: var currDoc:NotesDocument
Not sure if the title is quite right for the question but I can't
not sure what is wrong with this jquery code: http://jsfiddle.net/aCABM/ I want to to
Not sure why but I am not getting anything back from the json call.
Not sure where to post this, but I can't find any information anywhere and
Not sure if these two can be compared, to bear with me. But what
Not sure entirely what is happening, but I get the following errors from Internet
Not sure this is possible but maybe you can help. I have a list,
Not sure whats wrong here the error report says line 9, but when I
Not sure what to call it, but a combined solution for starting servers/logging/consoles/development would

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.