开发者

Return search results via JQuery Ajax and Classic ASP

开发者 https://www.devze.com 2023-02-22 11:53 出处:网络
I want to elim开发者_开发技巧inate postbacks when returning paged search results in a Classic ASP form. I thought I\'d use JQuery to hit an ASP page with the criteria and return the results from the s

I want to elim开发者_开发技巧inate postbacks when returning paged search results in a Classic ASP form. I thought I'd use JQuery to hit an ASP page with the criteria and return the results from the server to display in a table.

Should i use JSON here? What's the most efficient way to return the data so it's in tabular form? The options are I suppose to add the tags on the data that's returned from SQL, or have SQL add the presentation elements.


You can write an asp file where you query the database and write all the HTML you need to render the table, next you can write some jQuery to replace the table as follows:

var LastSearchCriteria = '';

function getMyQuery(){
  if (LastSearchCriteria != $.trim($("#txtSearchCriteria").val)
  {
    $.ajax({
      type:"POST",
      url: "MyQueryToDataBase.asp",
      dataType: "application/x-www-form-urlencoded",
      data: "Action=DoSearch&SearchCriteria="
        + jQuery.trim($("#txtSearchCriteria").val()),
      async: true,
      beforeSend : function(){
        $("#Loading").show(); //gif... just feed back
        LastSearchCriteria = $.trim($("#txtSearchCriteria").val());
      },
      success: function(msg){
        $("select[id$=MyTable]").remove();
        $("#fldMyTable").prepend(msg);
        $("#Loading").hide();
      }
    })
  }
}

You can also check jQuery.ajax() documentation


As ITroubs says, don't build HTML in the database.

Personally, I find it much easier to build the complete HTML in my ASP page and just render the HTML, rather than returning matching results in JSON format and then displaying it by building the elements in jQuery. I find it much easier to edit and maintain the HTML on an ASP page than changing the javascript thats building the display.

However, returning the results in JSON format does have its advantages. Its much more concise and easier to debug. It also will give you a lot more flexibility in what you can do with the results.


you could use jquery and a product like Flexigrid.

http://www.flexigrid.info/

This version uses ASP for the backend.

http://jamesowers.co.uk/asp-tutorials/63/flexigrid-with-asp-version-2/

I have used it.

0

精彩评论

暂无评论...
验证码 换一张
取 消