无法在 PhoneGap 应用程序中解析 JSON
Unable to parse JSON in PhoneGap app
我使用 PhoneGap Build 创建了一个简单的 PhoneGap 应用程序。我有一个 MySQL 数据库并编写了一个简单的 PHP 文件以从中读取一些数据并将其作为 JSON 格式提供。我尝试在 PhoneGap 应用程序的 HTML 文件中读取该信息,但我的手机没有显示任何内容。谁能帮我找出问题所在?
我还在我的应用程序中添加了 cordova-plugin-inappbrowser 插件。
这是我使用的代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>READ JSON Example (AJAX)</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://phonegappro.esy.es/test/json.php",
crossDomain: true,
cache: false,
success: function(result){
var result=$.parseJSON(result);
$.each(result, function(i, field){
$("#output").append("Title: "+ field.title + " duration: "+field.duration +" Price:"+field.price+"<br/>");
});
}
});
});
</script>
</head>
<body>
<div id="output"></div>
</body>
我找到了答案:我添加了一个 PhoneGap Build 白名单插件,然后它在 android 设备上也能正常工作。这是插件:<plugin name="com.indigoway.cordova.whitelist.whitelistplugin" spec="1.1.1" source="pgb" />
此外,在我的 config.xml 文件中,我还有: <access origin="*"/>
我使用 PhoneGap Build 创建了一个简单的 PhoneGap 应用程序。我有一个 MySQL 数据库并编写了一个简单的 PHP 文件以从中读取一些数据并将其作为 JSON 格式提供。我尝试在 PhoneGap 应用程序的 HTML 文件中读取该信息,但我的手机没有显示任何内容。谁能帮我找出问题所在? 我还在我的应用程序中添加了 cordova-plugin-inappbrowser 插件。 这是我使用的代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>READ JSON Example (AJAX)</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://phonegappro.esy.es/test/json.php",
crossDomain: true,
cache: false,
success: function(result){
var result=$.parseJSON(result);
$.each(result, function(i, field){
$("#output").append("Title: "+ field.title + " duration: "+field.duration +" Price:"+field.price+"<br/>");
});
}
});
});
</script>
</head>
<body>
<div id="output"></div>
</body>
我找到了答案:我添加了一个 PhoneGap Build 白名单插件,然后它在 android 设备上也能正常工作。这是插件:<plugin name="com.indigoway.cordova.whitelist.whitelistplugin" spec="1.1.1" source="pgb" />
此外,在我的 config.xml 文件中,我还有: <access origin="*"/>