[英]Ajax To PHP converter get value from 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: 我需要的是:
I want to hide this "secretkey=123"
so visitor cannot see my secret key 我想隐藏此"secretkey=123"
因此访客看不到我的秘密钥匙
when call "xmlhttp.send();"
当调用"xmlhttp.send();"
return the value and I want to convert it to php like example 返回值,我想像示例一样将其转换为php
$getxmlhttp = xmlhttp.send();
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. 当我键入某些内容时,它将被称为调用函数,但是当我按Enter键时,如何禁用该输入或对我来说最好的建议是什么。
this is my site sample: http://stok.tk 这是我的网站示例: http : //stok.tk
for example type "YI 067"
例如输入"YI 067"
1 : You can't. 1:你不能。 The browser (and so the visitor) can always know wich page is called with wich URL and parameters 浏览器(因此访问者)始终可以知道使用wich URL和参数调用了wich页面
2 : You can't do it like that. 2:你不能那样做。 You need to get the value of your request into getstok.php
with the super global variables $_GET['your var']
您需要使用超级全局变量$_GET['your var']
将请求的值获取到getstok.php
3 : It's reloading the page because it's sending your form. 3:正在重新加载页面,因为它正在发送表单。 By default it send it to the same page. 默认情况下,它将发送到同一页面。 Just remove your <form>
只需删除您的<form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.