【问题标题】:jquery classic asp return HTML and recordcount/other datajquery 经典 asp 返回 HTML 和记录计数/其他数据
【发布时间】:2011-04-12 21:01:17
【问题描述】:

使用经典 ASP 对返回 HTML 的 asp 页面进行 JQuery ajax 调用。这很好用。现在,我不仅想返回 HTML,还想从我调用的页面返回一些数字,比如记录计数。我该怎么做?

这是我的 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。我希望它也能推出计数。

【问题讨论】:

    标签: jquery asp-classic


    【解决方案1】:

    您可以让您的 ASP 页面在响应中发送自定义 HTTP 标头,例如:

    XHR-Count: 5
    

    与:

    Response.AddHeader "XHR-Count", "5"
    

    然后在success 回调中获取此标头:

    $.ajax({
        type: "POST",
        url: 'test-ajax-handler.asp',
        data: jsonToSend,
        success: function(response, status, xhr) {
            var count = xhr.getResponseHeader('XHR-Count');
            alert(count);
            $('#output').append(response);
        },
        error: function() {
            alert("error");
        }
    });
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2011-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多