首页 > 解决方案 > 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 />

标签: ajax

解决方案


推荐阅读