2 回答
TA贡献1851条经验 获得超4个赞
第一个<button type="submit">Call</button>=><button type="button" id="submitButton">Call</button>
然后添加一些Javascript:
<script>
window.onload = function() {
const button = document.querySelector("#submitButton");
button.addEventListener('click', () => {
sendRequest();
alert('button clicked');
});
}
function sendRequest() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
const number = document.querySelector("#phone").value;
xhttp.open("POST", "/path/to/php/endpoint", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(`number=${number}`);
}
</script>
TA贡献1796条经验 获得超4个赞
使用带有 post 方法的 jquery ajax 调用:像这样:- html:
<form>
<input id="phone" type="tel" name="phone">
<button type="button" onclick="return send_number();">Call</button>
</form>
查询:
function send_number()
{
var post_data = { };
var phone = $("#phone").val();
post_data['phone'] = phone;
var APPUrl = 'App_receive_number.php';
$.ajax({
type: "POST",
url: APPUrl,
data: post_data,
cache: false,
success: function(res)
{
alert("Success! Sent!"); return true;
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Failed! Please Try Again!");
return false;
}
});
}
- 2 回答
- 0 关注
- 168 浏览
添加回答
举报