如何解决jquery classic asp返回HTML和recordcount /其他数据
| 使用Classic ASP对返回HTML的asp页进行JQuery ajax调用。很好现在,我不仅要返回HTML,还希望从调用的页面返回一些数字,例如recordcount。我怎么做? 这是我的AJAX呼叫:function sendCcbRequest(text) {
var jsonToSend = { text: escape(text) };
var jsonToSend={ id: 1,lastname: escape(text) } ;
$.ajax({
type: \"POST\",url: \'test-ajax-handler.asp\',data: jsonToSend,success: function(response) {
$(\'#output\').append(response);
},error: function() {
alert(\"error\");
}
}); // end ajax
}
它所称的页面只是response.write \的一些HTML。我希望它也能增加计数。
解决方法
以JSON格式返回您的数据,例如:
{\"html\":\"<div>This is your HTML<\\/div\",\"count\":3}
$.ajax({
type: \"POST\",url: \'test-ajax-handler.asp\',data: jsonToSend,dataType: \"json\",success: function(response) {
$(\'#output\').append(response.html);
$(\'#count\').html(response.count);
},error: function() {
alert(\"error\");
}
});
,您可以让ASP页在响应中发送自定义HTTP标头,例如:
XHR-Count: 5
与:
Response.AddHeader \"XHR-Count\",\"5\"
然后在success
回调中获取此标头:
$.ajax({
type: \"POST\",success: function(response,status,xhr) {
var count = xhr.getResponseHeader(\'XHR-Count\');
alert(count);
$(\'#output\').append(response);
},error: function() {
alert(\"error\");
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。