python - Jquery cross domain ajax request always error -



python - Jquery cross domain ajax request always error -

i trying create simple jquery mobile application. set follows:

jquery client running on localhost:9090/myapp. my server running on localhost:9010/paperboy since on windows, on server side using simple server creating using "bottle" python micro framework. the server returns json on request, can see in chrome or firefox. i have validated response , valid json.

the problem facing is, want client read json server response. since crossdomain issue, not able so. here ajax code client:

$.ajax({ url: "http://localhost:9010/paperboy/toi", type:"get", data:$(this), datatype:"jsonp", //jsonp:"callback", no back upwards on server success:function(result){ console.log("ajax result: " + result); }, error:function(e){ console.log("error :" + e); } });

and bottle server code is:

from bottle import route, run, template, response paperboy import gettoinews ''' phone call http://localhost:9010/paperboy/toi in browser''' @route('/paperboy/:source') def index(source='all'): print "requesting news list %s" % source resultjson = gettoinews() response.content_type = "application/javascript" homecoming resultjson run(host='localhost', port=9010)

however on running application getting "ajax origin policy error" went away 1 time added content type server. ajax phone call goes through without errors, invokes "error" handler. have tried various combinations in vain. 1 thing not figure out adding jsonp back upwards server. appreciate help in matter , give thanks in advance help. thanks.

you said yourself, since it's cross-origin call, default it's disallowed sop.

if you're in command of server (and are), can utilize cors allow request. work on modern browser. (though sadly in case of ie8 , ie9, you'll need jquery patch enable utilize of microsoft-specific xdomainrequest object rather standard xmlhttprequest; jquery team reject set in library. ie10 adds cross-domain handling xmlhttprequest.)

alternately, response json, utilize similar json-p instead, has advantage of working browsers (and without jquery patches).

python ajax json jquery bottle

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -