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\");
    }
});