jquery - jsonp callback problem -
i'm trying following code retrieve client ip, , works fine
<script type="text/javascript"> function getip(json) { var ip = json.ip; // alerts client ip address alert(ip); } </script> <script type="text/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
but when try $.ajax
nothing...
$.ajax({ type: "get", url: 'http://jsonip.appspot.com/?callback=getip', datatype: "jsonp", success: function getip(json) { alert("sucess"); var ip = json.ip; alert(ip); } }); });
plz help
$.ajax({ type: "get", url: "http://jsonip.appspot.com/?callback=?", // ^ // ---- note ? symbol ----------------| // jquery responsible replacing symbol // name of auto generated callback fn datatype: "jsonp", success: function(json) { var ip = json.ip; alert(ip); } });
jsfiddle demo here.
Comments
Post a Comment