Saturday, 15 January 2011

jquery - Ajax + corss domain + render json file -



jquery - Ajax + corss domain + render json file -

i added ajax phone call in local unable render response api because cross domain issue. have 1 idea.i saved response in json file. 1 time run file means(in local) means response in local json file if run in server means want response server. dont want manual checking localhost/server. used code this. want generic method this. function checklocalhost() { if (window.location.href.indexof("localhost") > -1) { homecoming true; } else { homecoming false; } } if (checklocalhost()) { var url = 'json/abcd.json'; } else { var url = 'http://abcd.com'; } $.ajax({ type : "post", url : url, info : info contenttype : "application/json; charset=utf-8", datatype : "json", success : function(data) { }, error : function(error) { console.log('vvvv'); } });

in above code checked domain localhost or not. run localhost means utilize abcd json file otherwise utilize server api.

any thought ?

jquery ajax json

No comments:

Post a Comment