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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:52:43+00:00 2026-06-12T16:52:43+00:00

I would not like to call asp.net server side code with jquery $.ajax .

  • 0

I would not like to call asp.net server side code with jquery $.ajax .
So I have written a pure javascript ajax file .But when I call webmethod,this do not work.
Can anyony help me out how correct this? THANK you very much .

ajax.js:

var ajax = {
    _params: null,
_callback: null,
 _xhr: null,
_createXHR: function () {
if (window.ActiveXObject) {
 _xhr = new ActiveXObject("Microsoft.XMLHTTP");     //IE
}
    else if (window.XMLHttpRequest) {
        _xhr = new XMLHttpRequest();      //FireFox,Chrome et.
    }
},

_ajaxcallback: function () {
    if (_xhr.readyState == 4) {
        if (_xhr.status == 200) {
            _callback.call(this, _xhr.responseText)
        }
    }
},

_changeParams: function () {
    var args = arguments[0];
    var s = "";
    for (var i in args) {
        s += "&" + i + "=" + args[i];
    }
    _params = s;
},

get: function (url, params, callback) {
    _callback = callback;
    ajax._createXHR();
    ajax._changeParams(params);
    if (null != _xhr) {
        _xhr.open('get', url + '?' + _params, true);
        _xhr.onreadystatechange = ajax._ajaxcallback;
        _xhr.send();
    }
},

post: function (url, params, callback) {
    _callback = callback;
    ajax._createXHR();
    ajax._changeParams(params);
    if (null != _xhr) {
        _xhr.open('post', url, true);
        _xhr.onreadystatechange = ajax._ajaxcallback;
        _xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        _xhr.send(_params);
    }
}
}

WebForm1.aspx

<head runat="server">
<title></title>
<script src="ajax.js" type="text/javascript"></script>
<script type="text/javascript">
    function ajaxtest() {
        var uid = document.getElementById("txtuid").value;
        var pwd = document.getElementById("txtpwd").value;
        ajax.post("WebForm1.aspx/GetModel", "{ 'uid':" + uid + ", 'pwd':" + pwd + " }", function (data) {
            alert(data);
        });
    }
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtuid" value="eeee" />
<input type="text" value="222" id="txtpwd" onblur="ajaxtest()"/>

WebForm1.cs:

     [WebMethod]
    public static string GetModel(string uid,string pwd)
    {

     return "1";
    }
  • 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-12T16:52:44+00:00Added an answer on June 12, 2026 at 4:52 pm

    In your markup you need to have a ScriptManager with EnablePageMethods set to true. Doing this will ensure you can call the methods you have marked up with [WebMethod].

    In your JavaScript you can then call your method like this: PageMethods.GetModel("userName", "password", OnSuccessMethod, OnFailureMethod); – you won’t need any of the ActiveXObject/XmlHttpRequest stuff if you do it this way, which keeps things much simpler.

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

Sidebar

Related Questions

I have an ASP.Net MVC 3 application that uses a jQuery .ajax call to
I have a Ajax call using asp.net scriptmanager. Which behind the scene takes the
My use-case: I already have a working ASP.NET application I would like to implement
I do not like to use the calendar from .NET, so I would like
the following code is not behaving like I would expect. Please help me understand
For starters, I'm new to ASP.NET Ajax stuff, and only getting back into JQuery
I would like my ASP.NET MVC app to execute a query once per day.
We have an ASP.NET MVC 4 application that links to legacy native code. The
I've an ASP.NET MVC3 application, and now I would like to offer a WCF
I need to call a Javascript function from the server side in Client side.

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.