[英]Replace ASP.NET AJAX with jQuery for ASHX call
I've been using the following to communicate with a Web Proxy for cross domain calls. 我一直在使用以下内容与跨域调用的Web代理进行通信。 I'm updating some code, and already use jQuery, and want to drop ASP AJAX because I only use it for this now. 我正在更新一些代码,并且已经在使用jQuery,并且想删除ASP AJAX,因为我现在只使用它。
Is it possible to do the following with jQuery only? 是否可以仅使用jQuery执行以下操作?
function download(proxyUrl, contentUrl, isJson, callback) {
var request = new Sys.Net.WebRequest();
request.set_httpVerb("GET");
var isCache = false;
var url = proxyUrl + "?url=" + escape(contentUrl) + (isJson ? "&type=" + escape("application/json") : "") + "&cache=" + (isCache ? "10" : "0");
request.set_url(url);
request.add_completed(function (executor) {
if (executor.get_responseAvailable()) {
var content = executor.get_responseData();
callback(content);
}
});
var executor = new Sys.Net.XMLHttpExecutor();
request.set_executor(executor);
executor.executeRequest();
}
download("/_layouts/teamfusion/WebProxy.ashx", "http://www.twitter.com", false, function(content) {
alert(content);
});
This should work: 这应该工作:
$.ajax({
url: url,
type: "GET",
dataType: "json",
contentType: "application/json",
complete: callback
});
Here is the documentation for jQuery.ajax . 这是jQuery.ajax的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.