【发布时间】:2018-10-08 15:25:48
【问题描述】:
我是 php 新手,并试图从 html 下拉表单中填充 php curl 请求变量。我希望此请求在选择时重新加载页面。下面的代码给出了这个错误
select.php:19 Uncaught TypeError: document.getElementById(...).submit 不是函数 变化时(select.php:19) 在 HTMLSelectElement.onchange (select.php:10)
<html>
<head>
</head>
<body>
<form method="post">
<select id="wipname2" name="wipname2" style='position: relative' onchange="change()">
<option value="site1.com">site1.com</option>
<option value="site2.com">site2.com</option>
<option value="site3.com">site3.com </option>
</select>
</form>
<script>
function change(){
document.getElementById("wipname2").submit();
}
</script>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
//CURLOPT_URL => 'https://example.com/MagicService/rest/ltmNode?wipNames='.$_GET["wipnames2"],
CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=".'$_GET["wipnames2"]',
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=content.gslb.fmr.com",
// CURLOPT_URL => "https://example.com/MagicService/rest/ltmNode?wipNames=$value",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Cache-Control: no-cache",
"access-token: df11c69eabb9eab4abaf4bcc6b1e62a26025e830",
"password: ",
"username: "
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//fwrite($output,$response);
//print_r (explode(" ",$response));
echo $response;
}
?>
</body>
</html>
【问题讨论】:
-
你可以把
<form method="post">改成<form id="theForm" method="post">再把document.getElementById("wipname2").submit();改成document.getElementById("theForm").submit(); -
感谢@Hackerman 这工作得很好
-
@很高兴为您提供帮助!
-
请不要在评论区发布答案。
-
任何人都可以解释为什么 url 最后不能使用这个 '.$_GET["theForm"]
标签: javascript php ajax curl html-select