admin管理员组文章数量:1414923
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 ?
1 Answer
Reset to default 4It 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!
本文标签: javascriptAjax POST to another serverovercoming the cross domain restrictionsStack Overflow
版权声明:本文标题:javascript - Ajax POST to another server - overcoming the cross domain restrictions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745188150a2646781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论