firefox - Error in calling jsonrpc service in jquery -
i have jsonrpc web service deployed on redhat linux ami. can access service in python given below:
>>> import jsonrpclib >>> server=jsonrpclib.server(redhat_linux_ami_jsonrpc) >>> x=server.addmicroelement('test test test') >>> x u'first insert'
where , redhat_linux_ami_jsonrpc = jsonrpc service hosted on redhat linux ami
but when try call in jquery, works in ie fails in firefox. code have written given below:
var req = {jsonrpc:'2.0', method: 'addmicroelement',id:(new date).gettime()}; req.params=['new new new']; $.support.cors = true; $.ajax({ crossdomain: true, url: redhat_linux_ami_jsonrpc, data: json.stringify(req), type: "post", contenttype: "application/json", success: function(rpcres) { alert(rpcres.result); }, error: function(err, status, thrown) { alert(status); } });
where , redhat_linux_ami_jsonrpc = jsonrpc service hosted on redhat linux ami. says "cross-origin request blocked". how resolve this?
the "problem" cross-domain requests no longer allowed security reasons.
a possible solution using cross-origin resource sharing (cors), though don't yet have experience this:
http://enable-cors.org/ (obtained https://stackoverflow.com/a/18509333/1245352)
another possibility use {datatype: 'jsonp'}
, json padding. unfortunately, automatically sets request 'get'
instead of 'post'
, you're using. possible workaround change webservice use 'get'
method instead. there bunch of hacks post data jsonp: post data jsonp
you can try using curl
wrapped php script make request, , return results.
Comments
Post a Comment