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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:30:10+00:00 2026-05-25T14:30:10+00:00

I have a 2 ajax functions on my page. One that works when a

  • 0

I have a 2 ajax functions on my page. One that works when a link inside a grid is clicked and one when a button is clicked. The one from the grid works perfectly. However, the function from the click of a button produces an error every time.

Can someone please tell me where i am going wrong here. I would appreciate any help. Here is the one that fails:

    function createSource() {
        $.ajax({
            type: "POST",
            url: "Test.aspx/createSource",
            data: '{"schoolID":"' + $('#ddSchools').val() + '","vendor":"' + $('#txtVendor').val() + '","tSource":"' +  $('#txtTSource').val()+ '"}',
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (xhRequest, ErrorText, thrownError) {
                alert(thrownError);
            }
        });
    }

The Webmethod will have more code to it but i cant seem to hit it anyway. Here is the webmethod:

[WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
public static string createSource(int schoolId, string vendor, string tSource)
{
    try
    {
        string status = "This is a test string!";

        return status;
    }
    catch
    {
        throw new Exception("Could not create source code!");
    }
}

Also how can i go about getting the exact error that is causing this function to fail?

Thank you in advance for any help!!


ok so i figured where the problem is but i still do not have a solution. There actually wasn’t anything wrong with the code. I plugged the code in at document.ready and it fired correctly. However, it will not fire correctly whenever the button is clicked. The button is nothing special either. It is a simple input button.

<input id="cmdSubmit_Create" value="Submit" type="submit" />

any ideas?

For reference i will put the code that works on the document.ready:

$(document).ready(function () {
    $.ajax({
            type: "POST",
            url: "Test.aspx/createSource",
            data: '{"schoolId":"2236","vendor":"test","tsource":"test1234"}',
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert("status: " + textStatus + " errorThrown: " + errorThrown);
            },
            complete: function (jqXHR, textStatus) {
                alert("status: " + textStatus);
            }
        });
});

[WebMethod]
public static string helloWorld(string schoolId, string vendor,string tsource)
{
    try
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("Hello World! " + schoolId + '-' + vendor + '-' + tsource);

        return sb.ToString();
    }
    catch
    {
        throw new Exception("Could not create source code!");
    }
}

If i try to call the same webmethod on the click of cmdSubmit_Create it doesnt work:

       $('#cmdSubmit_Create').click(function () {
        $.ajax({
            type: "POST",
            url: "Test.aspx/helloWorld",
            data: '{"schoolId":"2236","vendor":"test","tsource":"test1234"}',
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (xhr, status, error) {
                alert('error' + error)
            }
        });
  • 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-05-25T14:30:11+00:00Added an answer on May 25, 2026 at 2:30 pm

    use following code

    $('#cmdSubmit_Create').click(function () {
        $.ajax({
            type: "POST",
            url: "Test.aspx/helloWorld",
            data: '{"schoolId":"2236","vendor":"test","tsource":"test1234"}',
            contentType: "application/json",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (xhr, status, error) {
                alert('error' + error)
            }
        });
        return false;
    });
    

    http://cmsnsoftware.blogspot.com/2011/01/how-to-call-csharp-function-in-ajax.html

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

Sidebar

Related Questions

I have two functions, one that makes an Ajax request when the user loads
I have 2 elements on my page that use Ajax. One is a simple
I am new to jQuery / AJAX. I have a page that uses colorbox
I have a site that calls AJAX. It works at my office, where I
I have two sortable lists that are connected. One is simply on the page,
I have a bit of javascript that I have used successfully on one page,
Working on an AJAX website (HTML,CSS,JavaScript, AJAX, PHP, MySQL). I have multiple javascript functions
I have an AJAX function inside a javascript file and I want it to
I have a jquery-ajax function that sends data to a php script and the
I have written a simple jQuery.ajax function which loads a user control from the

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.