开发者

Load Tracking Script on Form Submit

I'm trying to load a StatCounter tracking script after the form has been successfully sent. Here's the code:

$.ajax({
  type: "POST",
  url: "css/sendmail.php",
  data: dataString,
  success: function(data) {
    $('#script').load('css/script.html', function() ({
      $('#overlay').css('visibility','hidden');
      clearForm();
   $('#alert').slideDown().delay(5000).slideUp();
    });
  }
});

This is the tracking script:

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=3886809; 
var sc_invisible=1; 
var sc_security="05496a3d"; 
</script>

<script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><div class="statcounter">
<a title="visit tracker on tumblr" href="http://www.statcounter.com/tumblr/" target="_blank">
<img class="statcounter" src="http://c.statcounter.com/3886809/0/05496a3d/1/" alt="visit tracker on tumblr" ></a></div></noscript>
<!-- End of StatCounter Code -->开发者_如何学C;

I checked my stats and it works. The only problem is that the code is being executed twice. The first one shows up as "http://example.com/index.html" and the second one as "http://example.com/index.html#".


Couldnt it be just as simple doing it like

<div style="display:none" id="tracker">
<!-- PUT STATCOUNTERHERE -->
</div>

and in the success function do the following

$('#tracker').show();

The other way would to store the code as a var

var statcode = "<script> blahblahblah.....";

and then on success

$('#whereuwanttoshowit').html(statcode);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜