2010-08-23 23 views
0

我正在为基于位置提取天气信息的iphone编写应用程序。天气馈送在一个设定的位置正常工作。我创建了一个解析器,它根据一个程序化的叫做instamapper的GPS坐标获取GPS坐标,该坐标以csv格式在线发布坐标。我可以在HTML文件内的IE中执行代码并查看我的结果。然而,因为iPhone使用Safari,我想看看我的输出是什么。当我在Safari中运行代码时,没有任何事情发生,至少它发生了,我没有得到任何输出。我怎样才能看到我的输出?在Safari中运行Ajax

function fetchgps(callback) { 
    var url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247"; 

    var myRequest = new XMLHttpRequest(); 
    myRequest.onreadystatechange = function(e) {gps_xml_loaded(event, myRequest, callback);} 
    myRequest.open("GET", url); 
    myRequest.setRequestHeader("Cache-Control", "no-cache"); 
    myRequest.setRequestHeader("wx", "385"); 
    myRequest.send(null); 

    return myRequest; 
} 

function gps_xml_loaded(event, this_request, callback) { 
    if (this_request.readyState == 4) { 
    if (this_request.status == 200) { 
     var obj = {error:false, errorString:null} 
     var data = this_request.responseText; 
     if (data == null) { 
     callback(constructError("no <data>")); 
     return; 
     } 

     collected=data.split(","); //parses the data delimited by comma and put data into array 
     obj.latitude = collected[3]; 
     obj.longitude = collected[4]; 
     callback(obj); 
    } 
    else { 
     callback ({error:true, errorString:"Not Ready"}); //Could be any number of things.. 
    } 
    } 
} 

function dealwithgps(obj) { 
    if (obj.error == false) { 
    lat = obj.latitude; 
    lon = obj.longitude; 
    document.write("Latitude "+lat); 
    document.write("Longitude "+lon); 
    } 
    else { 
    document.write("error detected"); 
    } 
} 

fetchgps(dealwithgps); 

回答

0
console.log('output string' + orVariable); 

将登录到控制台(CMD + Alt + I打开控制台)在Firefox
作品也与Firebug扩展

+0

我使用的是Windows机器...别不认为有一个cmd键。 – cameron213 2010-08-23 00:42:35

+0

oopsie,我的坏。 这是来自Mac,但我用它在Windows上,它是非常接近相同的... 打开您的浏览器的首选项。转到高级选项卡或按钮。选中菜单栏中的Show Develop选项。点击菜单栏中的新选项“开发”,然后转到“显示Web检查器”。打开后,进入控制台,你应该看到你的console.log(“stufffff”)输出。您还可以使用控制台与您的页面进行交互,并触发您在全局范围内可用的任何功能。我希望这可以工作!控制台很棒。 – mraaroncruz 2010-08-23 23:23:58

相关问题