javascript - Ajax POST to another server - overcoming the cross domain restrictions - Stack Overflow

Is the only proper way to achieve this by using a proxy? I'm working on a clicktail clone (web use

Is the only proper way to achieve this by using a proxy? I'm working on a clicktail clone (web user interaction & mouse tracking analytics) and what I have so far is a script that will track all the user interactions and will post them to my server and save to the database, but the issue is if this script is added to a client who will be on another domain, the Ajax post will fail due to the cross domain scripting restrictions.

from reading about this, there are some hacks, but im keen to avoid them. It seems that a proxy is the only way round this. But that in turn poses a larger issue for me as any client who wishes to use my clicktail clone will also have to setup a proxy in addition to added javascript on their. This will be straight forward for a webmaster with a PHP site, as I can provide the script and they just bang it on their server, but for sites, they would have to include that in their solution and repile, maybe i could provide a dll, but even that would have to be referenced.

I have been reading about this HTML 5 window.postMessage -> and this jquery plugin / this looks good, and I think ill be able to use it to playback the captured user interactions, using Iframes but It doesn't, (at least I cannot see how) resolve the issue with cross domain AJAX posting. if you were in my situation, could you post your possible solution ?

Is the only proper way to achieve this by using a proxy? I'm working on a clicktail clone (web user interaction & mouse tracking analytics) and what I have so far is a script that will track all the user interactions and will post them to my server and save to the database, but the issue is if this script is added to a client who will be on another domain, the Ajax post will fail due to the cross domain scripting restrictions.

from reading about this, there are some hacks, but im keen to avoid them. It seems that a proxy is the only way round this. But that in turn poses a larger issue for me as any client who wishes to use my clicktail clone will also have to setup a proxy in addition to added javascript on their. This will be straight forward for a webmaster with a PHP site, as I can provide the script and they just bang it on their server, but for sites, they would have to include that in their solution and repile, maybe i could provide a dll, but even that would have to be referenced.

I have been reading about this HTML 5 window.postMessage -> and this jquery plugin http://benalman./projects/jquery-postmessage-plugin/ this looks good, and I think ill be able to use it to playback the captured user interactions, using Iframes but It doesn't, (at least I cannot see how) resolve the issue with cross domain AJAX posting. if you were in my situation, could you post your possible solution ?

Share Improve this question asked May 7, 2011 at 10:52 JGilmartinJGilmartin 9,32814 gold badges72 silver badges90 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

It seems that cross-domain POSTs are really possible in your situation. Here How do I send a cross-domain POST request via JavaScript? discussed the availability to configure the receiving server with Access-Control-Allow-Origin. After that you can do POST via jQuery:

$.ajax({
    type: 'POST',
    url: 'https://to./postHere.php',
    crossDomain: true,
    data: '{"some":"json"}',
    dataType: 'json',
    success: function(responseData, textStatus, jqXHR) {
        var value = responseData.someKey;
    },
    error: function (responseData, textStatus, errorThrown) {
        alert('POST failed.');
    }
});

Good luck!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745188150a4615734.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信