json - IP Lookup in PHP from JavaScript returning undefined -


i'm trying iplookup script.js through call own server, returned 'undefined'. why?

iplookup.php

<?php     header('content-type: application/json; charset=utf-8');     $data = json_encode($_server['remote_addr']);     //next line needs commented out     //echo $_get['callback'] . '(' . $data . ');'; ?> 

script.js

//get ipaddress $.ajax({     url: "http://www.example.com/iplookup.php",     data: null,     type: 'get',     crossdomain: true,     datatype: 'jsonp'  }).done(function (json) {     self.ip = json; }); //on next line returns `undefined`   console.log('ipaddress: ' + self.ip); 

you need echo response out also. right doing, set header, encode $_server['remote_addr'] $data variable, neber echo out. javascript ajax request gets empty response.

do so:

<?php  header("content-type: application/json"); print json_encode($_server['remote_addr']);  ?> 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -