Ecshop backstage through Ajax search principle

Source: Internet
Author: User

Ecshop search is actually very powerful, but ecshop search function foreground and backstage is not the same, the front desk is mainly through get way, submit the URL for paging, and in the background of Ecshop, is to accept the form of the search conditions, Then publish to Ajax via JS. Finally, the results are returned by Ecshop Ajax. Then the final search results are displayed.

Let's give an example, the detailed analysis of the ecshop backstage through the Ajax way to search.

For example, we search for return orders by Ecshop the Ajax way behind the scenes.

1: You must add the following search box in the HTM, order number <input type= "text" name= "ORDER_SN" size= ""/>

Ajax in 2:html can be written in the following format

listtable.filter[' order_sn '] = Utils.trim (document.forms[' searchform '].elements[' order_sn '].value);
listtable.filter[' page '] = 1;

Listtable.loadlist ();

We can see the following, that is, through Listtable.loadlist (), to trigger the Ajax.

3: Let's look at the PHP call again.

$result = Get_filter ();

if ($result = = = False)
{

If the returned result is empty, then the AJAX result filter

     $filter [' invoice_no ']   = Empty ($_request[' invoice_no '])? ': Trim ($_request[' invoice_no ');
        if ($_request[' is_ajax ') = = 1)
         {
            $filter [' order_sn '] = Json_ Str_iconv ($filter [' order_sn ']);
       }
        $filter [' sort_by ']    = Empty ($_request[' sort_by ']) ? ' CID ': Trim ($_request[' sort_by ');
        $filter [' sort_order '] = Empty ($_request[' sort_order ')? ' DESC ': Trim ($_request[' sort_order ');

$sql = "Select COUNT (*) from". $GLOBALS [' ECS ']->table (' Change ').
"WHERE 1". $where;
$filter [' record_count '] = $GLOBALS [' db ']->getone ($sql);

$filter = Page_and_size ($filter);

/* Receive activity data */
$sql = "SELECT *".
"From". $GLOBALS [' ECS ']->table (' Change ').
"WHERE 1". $where.
"ORDER by $filter [sort_by] $filter [Sort_order] LIMIT". $filter [' Start ']. ",". $filter [' page_size '];

$filter [' keywords '] = stripslashes ($filter [' keywords ']);
Set_filter ($filter, $sql);

}else{

$sql = $result [' sql '];
$filter = $result [' Filter '];

}

4: Finally returns the query result

$arr = Array (' res ' = = $row, ' filter ' + $filter, ' page_count ' = $filter [' Page_count '], ' record_count ' + $fil ter[' Record_count ');

return $arr;

In our analysis, RES is all the data returned, filter is the filtered search condition, Page_count is the number of pages, and Record_count represents the total number of records for the query.

Through the above package, we can successfully use AJAX to retrieve data in the Ecshop background

Ecshop backstage through Ajax search principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.