2014-03-01 2 views
0

에서 내가 코드다른 결과 요청 JSON은 PHP

jsfiddle

var url = 'http://ip.jsontest.com/';   
$.ajax({ 
    url: url, 
    dataType: "jsonp", 
    async: false, 
    success: function (result) { 
     alert('success'); 
    }, 
    error: function (request,error) { 
     alert(error); 
    } 
});   

에게 그 코드 수율 '성공'을 작업했다. 나는이 PHP 코드

<?php 
header('Content-Type: application/json; charset=utf-8'); 
$iii = array('ip' => '114.79.28.24'); 
echo json_encode($iii); 
?> 

와 'http://example.com'에 JSON의 URL (http://ip.jsontest.com/)을 변경할 때 나는 오류
어떤 문제가있어?

+2

무슨 오류? –

+0

'jsonp' <>'json'. –

+0

여기에 : http://stackoverflow.com/questions/2887209/what-are-the-differences-between-json-and-jsonp – Hardy

답변

0

dataType와 "JSON"없습니다 "JSONP"

var url = 'http://ip.jsontest.com/';   
    $.ajax({ 
    url: url, 
    dataType: "json", 
    async: false, 
    success: function (result) { 
     alert('success'); 
    } , 
    error: function (request,error) { 
     alert(error); 
    } 
});