Reputation: 934
I'm trying to automatically run an ajax url when my page is fully loaded using .load()
function. It seems my code doesn't work.
Other information:
The code is used for tracking affiliate users and is provided on the website for merchant users
I'm not sure of the jquery
version but I know my version doesn't accept $
, but only jQuery
The code:
$(window).load(function() {
$.ajax({
url: "https://shareasale.com/sale.cfm?amount=99.00&tracking=15&transtype=sale&merchantID=xxxxx"
});
});
Did I miss something? Thanks in advance.
Upvotes: 2
Views: 6968
Reputation: 93561
I am really puzzled why you need to load a tracking pixel via Ajax:
I used to work in SEO and we would just include the link to the tracking pixel in an image e.g. via
<img src="https://shareasale.com/sale.cfm?amount=99.00&tracking=15&transtype=sale&merchantID=49748" width="1" height="1">
.
Then you have no cross domain issues, no ajax, no worries.It just records on their site that the page loaded has your affiliate code (and probably drops a cookie at the same time).
Upvotes: 3
Reputation: 93
Please check the error in your browser console
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://shareasale.com/sale.cfm?amount=99.00&tracking=15&transtype=sale&merchantID=49748. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Upvotes: 0
Reputation: 576
This is completely working but just shows this error:
XMLHttpRequest cannot load https://shareasale.com/sale.cfm?amount=99.00&tracking=15&transtype=sale&merchantID=49748. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
This might not work from yout local host but will work properly from any server.
And still there is any error try this code:
$(document).ready(function(){
$.ajax({
url:'https://shareasale.com/sale.cfm?amount=99.00&tracking=15&transtype=sale&merchantID=49748',
success:function(data)
{
alert(data);
}
})
});
Upvotes: 1