[英]Loading Data from local MySQL server into Phonegap application
I'm trying to connect a MySQL server to my phonegap application. 我正在尝试将MySQL服务器连接到我的phonegap应用程序。 I currently have a localhost MySQL and Apache Server running on XAMPP. 我目前在XAMPP上运行localhost MySQL和Apache Server。 Here is my PHP script that I am using to call a simple SELECT statement on my server: 这是我用来在服务器上调用简单SELECT语句的PHP脚本:
<?php
$host="localhost";
$port=3306;
$socket="";
$user="root";
$password="";
$dbname="mydb";
$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server' . mysqli_connect_error());
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
$array = $result->fetch_row($result);
echo json_encode($array);
mysqli_close($con);
?>
Next, I make an jQuery JSON call within my javascript in order to obtain the information and simply print it out on my page. 接下来,我在JavaScript中进行了jQuery JSON调用,以获取信息并将其简单地打印在页面上。
$.ajax({
url: 'js/users.php',
dataType: 'json',
success: function(data){
var id = data[0];
var fName = data[1];
var lName = data[2];
$('#output').html("<b>id: </b>"+id+"<b> first name: </b>"+fname+"<b> last name: </b>"+lname);
},
error: function(data){
alert(JSON.stringify(data));
}
});
Yet whenever I attempt to run this code, the ajax call errors out and my browser returns a Status:200 and statusText:OK. 但是,每当我尝试运行此代码时,ajax调用都会出错,并且我的浏览器返回Status:200和statusText:OK。
I would really appreciate any help on this matter. 我真的很感谢在此问题上的任何帮助。 Thanks! 谢谢!
Thanks to @jcesarmobile, I was able to figure out my problem. 多亏@jcesarmobile,我才能够解决我的问题。 You cannot store your .php scripts within your project's directory. 您不能将.php脚本存储在项目目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.