2

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.

11
  • 1
    Is that your own website? Otherwise it may be a cross domain issue (designed to stop people embedding other people's web content) :) If that is not your website you would need to scrape their data from your web server instead (tut tut) :> Commented Dec 7, 2016 at 11:50
  • @GoneCoding it's a piece of code use for tracking affiliate users on that website. no it's not mine but this code is provided on the website for merchant users Commented Dec 7, 2016 at 11:52
  • 2
    Could also be because .load() was remove in JQuery v3. What version are you using? Commented Dec 7, 2016 at 11:52
  • That URL just returns a stock 1x1 pixel image to me (and I don't mean stock as in shares). Does their site require you to register the domain it will be used on with them? Commented Dec 7, 2016 at 11:53
  • your url returns this in return to me when i checked. shareasale.com/siteimages/1x1.png Commented Dec 7, 2016 at 11:56

3 Answers 3

3

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).

Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry if you got confused, seriously I also don't know, I just tried to use ajax to call the url. sorry I'm just a newbie
sir, how can i load the image containing the link? should i use javascript?
See above... just reference the URL in an image in the page somewhere.
1

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);
            }
        })
});

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.