inherit
97216
0
Nov 23, 2024 12:51:52 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Oct 23, 2011 15:09:24 GMT -8
Okay, so I've been running into some Cross-Domain jQuery $.get() and $.ajax() problems when trying to fetch information from another website. I've tried doing $.getJSON() and converting the page that is getting fetched from into a application/json but that still isn't working. How could I fetch cross-domain easily with jQuery? By the way, it's for a Proboards -> Regular Site, not Proboards->Proboards. (ex support.proboards.com -> google.com, but mine would be mysite.proboards.com -> anothersite.com/json/index.php?action=get-something&id=1) I've also thought about using iFrames for this but that would be far too elaborate for what I want to do. But if I were to use one iframe to then fetch stuff from, that would still be cross-domain AJAX wouldn't it? Thanks in advance. This has turned out to be a real bugger. EDIT: It turns out I just did it all on one site and iframed it on my PB. I'd still like to know some workaround for this in the future.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Oct 23, 2011 21:31:22 GMT -8
Ajax doesn't work cross-domain. It's a security feature.
Append a script to the <head> of the ProBoards document that points to anothersite.com/js/index.php?action=get-something&id=1, with that something returning a JavaScript function call instead of a string. It shouldn't be hard, since JSON is already value in JavaScript. I assume you now have:
ajax("mysite.com/page.php", function(text) { doSomethingWith(text); }); Where mysite.com/page.php returns something like {json here}
Change that to: if (var x = document.getElementById("ajax-script")) document.removeChild(x); var x = document.createElement("script"); x.setAttribute("id", "ajax-script"); x.setAttribute("src", "mysite.com/page.php"); document.getElementsByTagName("head").item(0).appendChild(x);
where mysite.com/page.php returns: doSomethingWith({json here});
|
|