Ryura,
You don't need to use getJSON but you do need to find out exactly how the
JSONP service you are using expects the callback function to be specified in
the URL. The echo you provided shows that the service you are calling is
not prepending the JSON encoded object with the name of the function.
Normally the GET param for a JSONP callback function is simply callback
-- I don't recall if jQuery will append this by default if it doesn't see a
? at the end of the provided URL -- but it can be anything. For example, it
could be jsonpCallback, in which case your URL should be something like:
http://somedomain.net/jsonp/selection.php?jsonpCallback=?
jQuery will autogenerate your callback function (which eventually will
invoke your success callback) and replace the trailing ? with the
autogenerated function name.
Scott
On Dec 28, 2007 12:42 PM, dfd [EMAIL PROTECTED] wrote:
Why not use getJSON?
From the docs http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback
As of jQuery 1.2, you can load JSON data located on another domain if
you specify a JSONP callback, which can be done like so: myurl?
callback=?. jQuery automatically replaces the ? with the correct
method name to call, calling your specified callback.
This is a piece of working code:
$.getJSON(http://ws.geonames.org/searchJSON?q=+m.editSearch
+featureClass=PfeatureClass=Acallback=?,
function(data){ // the callback-function, data came from geonames
if (data.totalResultsCount 0){
Regards, Frank
On 24 Dez., 22:31, Ryura [EMAIL PROTECTED] wrote:
Basically, I'm trying to pull data from a database on a different
server.
On the site without the database (we'll
sayhttp://thisdomain.com/index.html),
I have
var gomon = new Array();
gomon[0] = Test;
gomon[1] = Testx;
gomon[2] = Test3;
$.ajax({
type: GET,
url: http://somedomain.net/jsonp/selection.php;,
dataType: jsonp,
data: foo=+gomon,
success: function(gata){
alert(gata.go[3]].repping)
}
});
selection.php basically is echoing this:
({
go: [
{zepping:grrr,zamount:1,zepped:Ryura,tzme:2},
{zepping:garrr,zamount:1,zepped:Ryura,tzme:2},
{zepping:gsrrr,zamount:1,zepped:Ryura,tzme:2},
{zepping:grrrd,zamount:1,zepped:Ryura,tzme:2}
]
})
Now, when viewing thisdomain.com/index.html, Firebug gives me this
error:
[Exception... 'Permission denied to call method XMLHttpRequest.open'
when calling method: [nsIDOMEventListener::handleEvent] nsresult:
0x8057001e (NS_ERROR_XPC_JS_THREW_STRING) location: unknown
data: no]
And nothing executes. What did I do wrong?
Thanks,
Ryura
--
--
Scott Trudeau
scott.trudeau AT gmail DOT com
http://sstrudeau.com/
AIM: sodthestreets