jQuery技术:如何获得返回值.asp到ajax

为什么我不能从.asp获得返回值?

这是我的js:

$('#loginID').click(function(){ var userID = $("#userId").val(); var passID = $("#passwordId").val(); var myURL = "https://ipaddress/asp/test2.asp"; $.ajax({ type: "GET", url: myURL, dataType: "JSON", data: { username: userID, password: passID, }, success: function (response) { alert(response); } }); }); 

我的.asp:

   

编辑我只是注意到我的第一个js有问题,我正在做一个跨服务器ajax,但是看到了这个指南https://www.codeproject.com/Articles/185506/AJAX-Cross-Origin-HTTP-request (参考对于其他有相同问题的人)不要忘记添加Response.AddHeader“Access-Control-Allow-Origin”,“*”

 $('#loginID').click(function(){ var userID = $("#userId").val(); var passID = $("#passwordId").val(); var myURL = "https://ipaddresss from other server"+userID+"&password="+passID; var cor = null; if (window.XMLHttpRequest) { cor = new XMLHttpRequest(); } else { alert("Your browser does not support Cross-Origin request!"); return; } cor.onreadystatechange = function () { if (cor.readyState == 4) { var loko = cor.responseText; var obj = jQuery.parseJSON(loko); alert(obj.userID); } }; cor.open('GET', myURL, true); cor.withCredential = "true"; cor.send(null); }); 

无论如何问题解决了..只需要改进我的脚本

    看起来好像你正在使用aspjson 。

    这是一个应该有用的例子。

      <% Dim member, json Set member = jsObject() Dim conn, cmd, rs, sql Dim userid, pwd 'Use POST in your ajax to hide logon values from the URL userid = Request.Form("username") & "" pwd = Request.Form("password") & "" 'Your connection string should be stored in an #include so it can be easily accessed. conn = "Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=userid;Initial Catalog=SMS;Data Source=127.0.0.1" 'Use parametrised queries instead of being left open to SQL injection. sql = "SELECT * FROM USER_ID WHERE UserID = ? and password = ?" Set cmd = Server.CreateObject("ADODB.Command") With cmd 'No need for ADODB.Connection object, ActiveConnection will instantiate it for us when the ADODB.Command is executed using the connection string. .ActiveConnection = conn .CommandType = adCmdText 'equals 1 if constants not defined .CommandText = sql 'Assuming your fields (in order) are NVARCHAR with a length of 100 (change as appropriate. .Parameters.Append(.CreateParameter("@userid", adVarWChar, adParamInput, 100)) .Parameters.Append(.CreateParameter("@password", adVarWChar, adParamInput, 100)) Set rs = .Execute(, Array(userid, pwd)) If (Not rs.EOF) Then 'Populate jsObject member("userID") = rs("UserID") member("idMember") = rs("IDMember") Else 'Populate with error instead member("error") = 50 End If Call rs.Close() Set rs = Nothing End With Set cmd = Nothing 'Serialize JSObject to a JSON string json = toJSON(member) 'Output JSON response Response.ContentType = "application/json" Call Response.Write(json) %> 

    尽管如此

      以上就是jQuery教程分享如何获得返回值.asp到ajax相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/532570.html

      (0)
      上一篇 2020年12月21日
      下一篇 2020年12月21日

      精彩推荐