0

Im trying to build a counter for my links in many website I have. so every click on my links on other websites, my database will count them..

(every website is in another server..)

I tried to build some script in Jquery on every page that I want to make this happened:

$(document).ready(function() {

    attach();
});


function attach() {

    var name;
    var classCounter = $('.counterStrike');

    classCounter.bind('click', function() {

        var name = $(this).attr('name');

        var url = "http://XXXXX.######.XX/XXX/XXXX/Handler/Handler.aspx";
        var op = "1";
        var fromLocation;

        $.post(url, {
            name: name,
            op: op
        }, function(result) {
            alert(1);
            $("#result").html(result);

        });


    });


}

this worked fine in the same server, so I guess I have some cross browser problem ? right? is there a way to manipulate it ?

Thanks!

thormayer
  • 1,070
  • 6
  • 28
  • 49
  • Try review this http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp post. – StringBuilder Nov 04 '12 at 12:45
  • Why does your question say "POST" and your code say `$.get`? – Quentin Nov 04 '12 at 12:46
  • thanks @user1106128 do I need to use JSONP ? – thormayer Nov 04 '12 at 12:46
  • Yeah, you *can* **POST** to another web server via a normal form submit - what you *can't* do is an AJAX request (get or post) – techfoobar Nov 04 '12 at 12:47
  • @thormayer — We have insufficient information about your problem to determine if JSONP is a possible solution or if it is the best solution. – Quentin Nov 04 '12 at 12:47
  • The question title appears to be incorrect. There is no POST request here; only a GET request. Correct? – apsillers Nov 04 '12 at 12:49
  • @thormayer Do you know about the [same-origin policy](https://developer.mozilla.org/en-US/docs/Same_origin_policy_for_JavaScript) for Ajax requests? If not, that's the cause of your trouble. – apsillers Nov 04 '12 at 13:02

2 Answers2

2

You can use jsonp. It's used for cross-domain requests

Kirill Ivlev
  • 12,310
  • 5
  • 27
  • 31
-1

Maybe you can add for example new HttpHandler on your side that will make post from your server to remote and get data ,

then post via ajax to your httphandler like to a kind of proxy ...

StringBuilder
  • 1,619
  • 4
  • 32
  • 52