我有一个用于调用网页的 ajax 调用,我想得到结果。它的问题是它似乎不起作用,并且目前返回一个jQuery parse Error。
当我查看调试控制台并单击时,它会将我带到我想要的页面,它似乎并没有通过 ajax 完成并存储结果/调用成功。
我的代码:
$.ajax({
type: "GET",
url: "mywebsite",
data: {username: username, password:password},
dataType: "jsonp",
contentType: "application/json",
xhrFields: {withCredentials: true},
crossDomain: true,
success: function(result, status, jqxhr){ alert("success"); },
error: function(xhr, status, message){ alert(status + ": " + message); }
});
如您所见,我有一些要添加到其中的凭据,并且有人告诉我将其保存在数据中,而不是为用户名和密码执行 ajax 选项。
我不确定发生了什么,而且似乎有什么问题。我正在通过堆栈溢出查看 3 种不同的方法,但似乎没有一个能给我正确的答案。
发布数据
Request URL:http://10.224.65.5/mas3/DataSources/inspecttech.inspecttech/Schema/Classes?callback=jQuery17202808878293726593_1373384418801&username=njtax.hinspecttech&password=4e1cb7494843c513ee913d122e30ef2fe27635e5f82f575c92d006691906bebbbdb1fe483cfc06b087f7c4070c2879bd3585234a3614a1f04fca8de64ad6bfaf&_=1373384423017
Request Method:GET
Status Code:200 OK
Request Headersview source
请求标头
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Authorization:Basic bmRvdG1vYnguaG1vYmlsZWRldmljZTpzdXBlclNlY3JldERldmljZVBhc3N3b3Jk
Connection:keep-alive
Host:10.224.65.5
Referer:http://localhost:3033/BentleyFormIntegrationFrameset.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
查询字符串参数view sourceview URL 编码
callback:jQuery17202808878293726593_1373384418801
username:njtax.hinspecttech
password:4e1cb7494843c513ee913d122e30ef2fe27635e5f82f575c92d006691906bebbbdb1fe483cfc06b087f7c4070c2879bd3585234a3614a1f04fca8de64ad6bfaf
_:1373384423017
Response Headersview source
响应标头
Cache-Control:no-cache
Content-Language:en-US
Content-Length:801
Content-Type:application/json; charset=utf-8
Date:Tue, 09 Jul 2013 15:40:22 GMT
Expires:-1
Mas-License-Error-Id:NoClientLicense
Mas-License-Error-Message:Client's license is invalid.
Pragma:no-cache
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
附加信息
预览(在 Google Chrome 中)显示返回的对象,但我不确定它为什么会失败。看起来它正确地获取了所有内容。
通过 ASP 的可能替代选项?
HttpWebRequest request = HttpWebRequest.Create(Request.Url.Scheme + "://" + site +"/DataSources/inspecttech.inspecttech/Objects/DeviceDatabase/" +action) as HttpWebRequest;
NetworkCredential cred = new NetworkCredential(bic_name + "x.h" + user.in_username, user.in_password);
request.Credentials = cred;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
string resp = "";
StreamReader reader = new StreamReader(response.GetResponseStream());
while (!reader.EndOfStream)
resp += reader.ReadLine();