Joiskhicchoon
New Member
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: \[code\]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; } _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); }}}\[/code\]WebForm1.aspx\[code\]<head runat="server"><title></title><script src="http://stackoverflow.com/questions/12791811/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="http://stackoverflow.com/questions/12791811/eeee" /><input type="text" value="http://stackoverflow.com/questions/12791811/222" id="txtpwd" onblur="ajaxtest()"/>\[/code\]WebForm1.cs:\[code\] [WebMethod] public static string GetModel(string uid,string pwd) { return "1"; }\[/code\]