在 vanilla JavaScript 中向服务器发送 GET 请求的最佳方式是什么?
我有这个javascript代码
<Script>
function getGroupId(){
var group=document.getElementById("selectedOptions").value;
var groupFirstLetter=group.substring(2);
}
</Script>
Run Code Online (Sandbox Code Playgroud)
我需要传递groupFirstLetter给PHP函数,该函数将计算该组中有多少用户并将值返回给javascript函数.
有什么想法吗?
谢谢,
示例:假设当前页面url(window.location.href)是http://example.com/page.html html页面源代码是......
<html><head></head><body>
<script src="http://example.com/script.js?user=Ankit&ptid=18"></script>
</body></html>
Run Code Online (Sandbox Code Playgroud)
现在我需要在script.js中使用'src'变量并且脚本文件script.js应该返回
var a="Ankit"
var b="18"
Run Code Online (Sandbox Code Playgroud)
我们可以在php中使用echo $ _GET之类的东西吗?
我有以下 URL:http://localhost:8888/datatest?username=JD042719
我想拉入"JD042719". 此问题不需要“获取”请求。然后,用户名值应设置为另一个文本框的值。也许是这样的:
超文本标记语言
<label for="Assoc">Associate ID</label>
<input type="text" name="AssocID" id="AssocID" required="required">
Run Code Online (Sandbox Code Playgroud)
JavaScript
$(function associd(){
document.getElementById("AssocID").value=username;
});
Run Code Online (Sandbox Code Playgroud)