2013-08-22 72 views
1

我有页面跟踪/跟踪像素页面,目前使用$ .post(PAIRS-DATA)将在JavaScript中收集的信息发回服务器。然后最终加载为跟踪像素。跟踪像素跨域,ASP.NET,jQuery,AJAX

 finally 
     { 
      //tracking pixel 
      Response.ContentType = "image/gif"; 
      byte[] buffer = pix.BinaryData; 
      int len = buffer.Length; 
      Response.OutputStream.Write(buffer, 0, len); 

     } 

问题是,$ .post(PAIRS-DATA)在Chrome中被取消,因为它是跨域。所以,我想

  $.ajax({ 
      type: "POST", 
      dataType: "jsonp", 
      jsonp: false, 
      processData: false, 
      crossDomain: true,     
      url: "URL", 
      data: dataPairs 
     }); 

这需要跨域问题的关心,但我现在得到“资源解释为脚本,但与MIME类型的图像/ GIF转:

我怎样才能解决这个问题? $ .ajax调用有什么问题吗?

回答

1

您的ajax调用失败,因为JSONP要求服务器实际发回JSONP(即JSON +封装)。

如果您必须在加载图像之前使用JS收集数据,则可以尝试在图像的查询字符串中传递所需的数据。

实施例:

$(document).append('<img src="http://host.com/path/to/image?' + formatDataAsQueryString());

+1

所以,我去掉跟踪Response.ContentType = “图像/ GIF”; byte [] buffer = pix.BinaryData; int len = buffer.Length; Response.OutputStream.Write(buffer,0,len);并传回图像?这不会减慢速度吗? – esoteric