安全的移动应用程序与服务器的连接

时间:2020-04-07 15:44:04

标签: javascript php ajax web mobile

我正在使用Java脚本等网络技术创建移动应用程序。我的服务器正在运行php以连接到数据库。如果我要在数据库中插入/删除/更新某些内容,则Ajax需要传递信息。我知道使用该应用程序时没有人可以看到源代码,但是如果有人能以某种方式获取源代码,如何阻止用户查看我的服务器地址和php文件名?

示例代码(来自w3schools):

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    document.getElementById("txtHint").innerHTML = this.responseText;
  }
};
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();

1 个答案:

答案 0 :(得分:0)

我找到了方法

    <div id="testeFuncao">
        <script type="text/javascript">
            $("#butaoTeste").on("click", function(){
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    document.getElementById("txtHint").innerHTML = this.responseText;
                }
                };
                xmlhttp.open("GET", "gethint.php?q=" + str, true);
                xmlhttp.send();
            });

            $("#testeFuncao").remove();
        </script>
    </div>