【发布时间】:2015-07-31 23:35:45
【问题描述】:
我刚刚说过使用 XDK,我认为它是一款出色的软件。我想在我的 APP 中使用 PHP 文件并调用 XAMPP 数据库。
我知道我必须使用 jquery/AJAX 通过 PHP 文件进行连接。
我的第一步只是让 AJAX 调用与 JSON 一起工作。我不断收到错误,例如访问被拒绝,以及 localhost 服务器的 404 错误。
我已经在 XDK 中制作了我的 PHP 文件,这样可以吗,还是在使用 XAMPP 时我需要将它们放在我的 htdocs 中的其他位置。我的问题真的是我不知道我在修复什么。我认为定位我的 Xampp URL :localhost -> 然后文件路径就可以了。
我也不知道我的 jquery 是否正常工作。
这是我的 ajax/jquery/index 页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(e){
e.preventDefault(); // prevent the default action of the click
var fname = $("#name").val();
$.ajax({
type: "GET",
url: 'http://localhost/nearly/nearly/www/php/test.php;',
data: {fname: fname},
dataType: "jsonp",
jsonp: 'callback',
jsonpCallback: 'checkname',
success: function(msg){
msg=alert("hello");
}
});
});
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content">
<form method="get" >
<label for="name">First name:</label>
<input id="name" type="text" name="name" id="name">
<button id="btn1" type="submit">Go</button>
</form>
</div>
<div id="table"></div>
</div>
</body>
</html>
我的 PHP 是 test.php :
<?php
header("Content-Type: application/json");
$fname = $_GET['firstname'];
echo $_GET['checkname'] . '(' . "{'fullname' : '".$fname."'}" . ')';
}
?>
我不是 100% 了解上面的 JSON 我很少使用这种方法,但有人告诉我它最适合移动应用程序。
如果可能的话,如果有人可以就如何使用 Xampp mySQL 设置 XDK 提供一些建议,并让我知道我上面的代码是否会将任何内容返回到我的索引页面,以便我知道它的工作原理。
我可以使用保存在“www”项目中的 php 文件吗?可以找到绝对没有关于使用 XDK 设置 XAMPP 的文档。如果这是唯一的方法,我可以访问 Web 服务器,因此可以将文件放在那里。我确实花了 2 个漫长的夜晚试图解决我的问题 -
非常感谢任何帮助。对于 Xampp 问题,我的项目保存在我的 XAMPP 的 htdocs 中
【问题讨论】:
标签: php jquery ajax json intel-xdk