2013-08-28 75 views
2

我创建fisrtTest.php JSON对象的JSON是正确的,当我打开与WampServer此页面的jQuery移动..获取JSON与从本地主机

但我不能做一个Ajax请求:/ 为什么呢?跨域策略?

$.getJSON('http://localhost/tests/fisrtTest.php', 
    success 
); 

function success(data) { 
} 

这是与PhoneGap的

回答

0

什么是你的错误移动应用?你可以在firebug控制台中查看JSON响应吗? 下面是工作代码

$(document).ready(function(){ 
    $("#ibutton").click(function() { 
    alert("go"); 
      $.ajax({ 
       url: "http://localhost:8080/tests/fisrtTest.php", 
       dataType: "jsonp", 
       crossDomain: true, 
       jsonpCallback: "CallBackFunction" 
      }); 
    }); 
}); 


function CallBackFunction(json){ 
// 
}; 
+0

当我打开http://localhost/tests/fisrtTest.php时,我可以看到JSON: {“a”:1,“b”: 2,“c”:3,“d”:4,“e”:5} 但是,如果我用你的代码创建一个html页面。什么都没发生。 Firebug只显示一些cordova问题。 – user2306385

+0

我改变了代码。你可以试试吗? –

0
$(document).ready(function(){ 
    $("#ibutton").click(function() { 
    alert("go"); 
      $.ajax({ 
       url: "http://localhost:8080/tests/fisrtTest.php?callback=?", 
       dataType: "json", 
       crossDomain: true, 
       success: function(data) { 

       } 
      }); 
    }); 
}); 

好了,这工作,但萤火得到一个错误:

语法错误:无效的标签 { “杰克”:1, “GT”:2, “C” :3,“d”:4,“e”:5}