0

I have working code

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);
    }
});         

That code yield 'success'. But when i change the json url (http://ip.jsontest.com/) to 'http://example.com' with this PHP code

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

I got an error
What's wrong?

prasastoadi
  • 2,536
  • 2
  • 16
  • 14

1 Answers1

0

dataType: "json" not "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);
    }
 }); 
Victorino
  • 1,623
  • 11
  • 22