gpt4 book ai didi

php - phonegap- 使用 Eclipse 就绪状态 0 responsetext 状态 0 statustext 错误

转载 作者:可可西里 更新时间:2023-11-01 09:05:45 30 4
gpt4 key购买 nike

我正在尝试使用 ajax 请求访问 phonegap 应用程序上的 mysql 数据库数据。它在 php 中运行得非常好,但是当我尝试在 phonegap 上运行它时,它给了我一个烦人的错误 -请找到代码:

                   <script>
$(document).ready(function () {
$("#btnclick").click(function () {
$.ajax({
url: "http://192.168.1.16:8080/api.php",
datatype: "json",
ContentType:"application/json",
success: function(respose)
{
alert("It works !!");
alert(JSON.stringify(respose));
},
error: function(err)
{
alert("It failed ");
alert(JSON.stringify(err));
}
});
});
});
</script>
</head>
<body>
<p>This is a paragraph content</p>

<h1>Call API from Php</h1>
<input type="button" value="login" id="btnclick" />
</body>

这是我的 php api:api.php

            <?php
header('Access-Control-Allow-Origin: *');

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ajax01";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

else
{

//if(isset($_GET['Username']))
{
//$username = $_GET['Username'];
//$password = $_GET['Password'];

$mysql_user = "root";
$mysql_password = "";
$database = "ajax01";


$link = mysqli_connect("localhost","$mysql_user","$mysql_password","$database") or die("Error " . mysqli_error($link));

$query = "SELECT * FROM logintable" or die("Error in the connection" . mysqli_error($link));


//execute the query.

//$query = "update logintable set id='5' where id='1' " or die("Error in the connection" . mysqli_error($link));


$result = mysqli_query($link, $query);

$totalRows = mysqli_num_rows($result);

while($row = mysqli_fetch_array($result))
{
echo $row["id"] . $row["name"] . $row["password"] ;
}


}
}
?>

phonegap 中的错误是:readystate 0 responsetext status 0 statustext error

尽管相同的代码在网络服务器上运行良好。帮助!!

最佳答案

这可能对你有帮助

sudo cordova 插件添加 https://github.com/apache/cordova-plugin-whitelist

现在你有了这个插件,在你的 config.xml 中添加这一行

<allow-navigation href="http://192.168.1.16:8080/*" />

重建并重试!

关于php - phonegap- 使用 Eclipse 就绪状态 0 responsetext 状态 0 statustext 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31312707/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com