AJAX呼叫在Phonegap中不起作用,但正常工作 [英] AJAX Call not working in Phonegap but working normally

查看:73
本文介绍了AJAX呼叫在Phonegap中不起作用,但正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用开放式天气地图api网络服务进行ajax调用,以便使用经度和纬度获取当前天气,问题是同一调用在我的普通php文件夹中有效,但在我的phongap应用程序中不起作用.我的ajax调用如下所示

i am using the open weather map api webservice to make an ajax call inorder to get the current weather using the latitude and longitude the problem is the same call works in my normal php folder but it doesnt work in my phongap app. My ajax call is as shown below

$.ajax({
        type : "GET",
    dataType: "jsonp",
        url  : "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139",
    }).done( function(msg){
     var response = JSON.stringify(msg);
     var parsedResponse = JSON.parse(response);
     alert(parsedResponse.main.temp_min);
    });
});

我尝试了不使用dataType: "jsonp"尝试将其更改为"json"的方法,但是没有任何效果.请帮助我,因为我目前对此仍然感到困惑.

I have tried without dataType: "jsonp" tried changing it to "json" but nothing works at all. Please help me as I am stuck on this currently.

推荐答案

您是否已将config.xml中的网址列入白名单?

Have you whitelisted the url in your config.xml?

<access origin="http://api.openweathermap.org" />

了解更多: http://docs .phonegap.com/en/3.0.0/guide_appdev_whitelist_index.md.html#Domain%20Whitelist%20Guide

这篇关于AJAX呼叫在Phonegap中不起作用,但正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆