A click-by-count function implemented via Ajax

Source: Internet
Author: User
Tags count

Writing a very simple function today is only a summary.

The basic flow of clicks is this: at the point of the link, first go to a statistical address you set, and then redirect to the real address.

I'm using AJAX to implement this process. In order to realize the link and advertising public this function.

Let's talk about the background code section.

First is the link section, he is the background code generated HTML code as follows

_GoodLink1.Append("·<a href='" + dr["LJDZ"] + "' target='_blank' title='" + dr["LJMC"] + "' onclick=\"UpdateTraffs ('LINK_TAB','LJID'," + dr["LJID"] + ",'DJCS')\">").Append (dr["LJMC"]).Append("</a>");

Then is the advertisement part, the advertisement part is by the code generation dynamic JS again by the page references JS display advertisement, below is the key code;

sb.Append("' target='_blank' onclick=\\");sb.Append ("\"javascript:UpdateTraffs('AD_TAB','GGID'," + dv.Table.Rows[k] ["GGID"] + ",'DJCS')\\");sb.Append("\">

The most important part of this is the use of the variable, so as to ensure that in JS is onclick=\ "javascript:updatetraffs ' ad_tab ', ' Ggid ', 1, ' DJCS ') \" form

The key to the transfer of intermediate data parameters is JS code as follows

function UpdateTraffs(tabName,mainkey,keyValue,column)//要验证的控件ID,验证的结果, 验证的类型email|user
   {
     var http_request;
     if (window.XMLHttpRequest)
     {//对于Mozilla、Netscape、Safari等浏览器,创建XMLHttpRequest对象
       http_request = new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {// 对于Internet Explorer浏览器,创建XMLHttpRequest
       try
       {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch (e)
       {
         try
         {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (e)
         {}
       }
     }
     http_request.open("POST","/Function/Traffic.aspx? _tabName="+tabName+"&&_mainkey="+mainkey+"&&_keyValue="+keyValue+"&& _column="+column+"",false);    
     http_request.send();
   }

Related Article

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.