var URL_page = "http://120.77.101.21/pg_logs/";/***********************ajax发送数据***************************/// 只能使用get方式,post方式后台接收不到数据function getData(type, functionName, requestdata){ return $.ajax({ type: type, url: functionName, dataType: "json", //contentType: "application/json;utf-8", data: requestdata, timeout: 6000 });};/***********************ajax发送数据***************************/$(function(){ // 获取url参数 function GetQueryString(url,name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = url.match(reg); if(r!=null)return unescape(r[2]); return null; } var pageLogs=$("#pageLogs"); var channel=pageLogs.attr("channel"); var appsku=pageLogs.attr("appsku"); var key=pageLogs.attr("key"); var zt=pageLogs.attr("zt"); var url=window.location.href; getData("post", URL_page+"h5PageLogs/saveSubject", {channel:channel, appsku:appsku, key:key, zt:zt, url:url}) .done(function (response) { //alert("===:"+response); }); // 给所有有carName属性的a标签绑定click事件!!! $("a[carName]").bind("click",function(){ var href = $(this).attr("href"); var carName = $(this).attr("carName"); var position = $(this).attr("pos"); //alert(position); var hrefs=href.split("?"); var serialId = GetQueryString(hrefs[1],"serialId"); var carId = GetQueryString(hrefs[1],"carId"); // alert(serialId);// alert(carId); if(serialId==null){// alert("serialId为null"); var hrefInfo = hrefs[0].split("/"); serialId = hrefInfo[hrefInfo.length-3]; carId = hrefInfo[hrefInfo.length-2]; } if(isNaN(serialId)){ //alert('不是数字!'+serialId); serialId = $(this).attr("serialId"); carId = $(this).attr("carId"); } if(serialId=="auction"){ serialId = $(this).attr("serialId"); carId = $(this).attr("carId"); } getData("post", URL_page+"h5PageLogs/saveClick", {channel:channel, appsku:appsku, key:key, zt:zt, serialId:serialId, carId:carId, carName:carName, position:position}) .done(function (response) { //alert("saveClick:"+response); }); });});
使用:
这里输入代码
<script src="http://120.77.101.21/pg_logs/static/1.9.1/pageLogs.js" id="pageLogs" channel="${pd.channel}" appsku="${pd.appsku}" key="${pd.key}" zt="${pd.zt}" type="text/javascript" ></script>