dongxun3777 2017-12-09 08:03
浏览 34
已采纳

Ajax To PHP转换器从ajax获取值

i need help, here my code :

<html>
<head>
<script>
function showHint(str) {
    if (str.length == 0) { 
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET", "getstok.php?secretkey=123&sku=" + str, true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>
<p><b>Masukkan kode barang / SKU:</b></p>
<form> 
Kode Barang: <input type="text" onkeyup="showHint(this.value)">
</form>
<div id="txtHint"></span>
</body>
</html>

What I need is:

  1. I want to hide this "secretkey=123" so visitor cannot see my secret key

  2. when call "xmlhttp.send();" return the value and I want to convert it to php like example

    $getxmlhttp = xmlhttp.send();

  3. when I type something it will be call function, but when I press enter that refresh, how to disable the enter or what the best suggestion for me.

this is my site sample: http://stok.tk

for example type "YI 067"

  • 写回答

1条回答 默认 最新

  • doubi4617 2017-12-09 08:13
    关注

    1 : You can't. The browser (and so the visitor) can always know wich page is called with wich URL and parameters

    2 : You can't do it like that. You need to get the value of your request into getstok.php with the super global variables $_GET['your var']

    3 : It's reloading the page because it's sending your form. By default it send it to the same page. Just remove your <form>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度