ajax - AJAX 没有向 php 提交数据
问题描述
我有一个表单,它收集一些数据,然后将数据存储到局部变量中,一切正常。然后我决定我也想将此数据发送到服务器上的 php 页面。
但是,当我添加 AJAX 代码时,一切都停止了,没有任何反应,这是为使用 cordova 的应用程序构建的,我似乎无法调试它。
window.onload = function()
{
document.addEventListener("deviceready", init, false);
}
function init()
{
document.getElementById("btnSave").addEventListener("click",saveData, false);
document.getElementById("btnGet").addEventListener("click", getData, false);
}
function saveData()
{
var user = document.getElementById("user").value;
var name = document.getElementById("name").value;
window.localStorage.setItem("user", user);
window.localStorage.setItem("name", name);
var deviceID = device.uuid;
window.localStorage.setItem("uuid", deviceID);
$.ajax({
type: "POST",
url: "http://www.mydomain.co.uk/folder/add.php",
data: {
user : user,
name : name,
},
success: function(response){
alert("Thank you your information has been saved");
}
});
}
和形式
<label>Username:</label>
<input name="user" type="text" placeholder="" id="user" class="stored form-control">
<label>Name:</label>
<input name="name" type="text" placeholder="" id="name" class="stored form-control">
<button id="btnSave">Save Data</button><br />
解决方案
推荐阅读
- javascript - 如何间接调用对象的键
- sql - 使用计算的键在 SQL 中聚合
- django - Django Query - 使用日期比较中的布尔值进行注释
- vue.js - 路由器推送后Vue更新状态
- php - PHP:如何使用参数在 Oracle 数据库中插入记录?
- algorithm - 为什么要在寻找替换之前在反向链接中标准化规则?
- javascript - 如何通过 id 将对象与 jquery 合并
- firebase - Firebase auth().onAuthStateChanged 不等到 auth().signInWithCredential 完成
- javascript - 将 Web 应用程序转换为 Lorca 桌面应用程序时出现 404(未找到)错误
- .net - ILogger - 冗余日志级别的资源利用率