[英]Ajax, JQuery, GET request with PHP error
I have a very basic webpage which contains of two files, phpcode.php.cgi and frontpage.php.cgi. 我有一个非常基本的网页,其中包含两个文件phpcode.php.cgi和frontpage.php.cgi。 I have dropdowns that should be populated dynamically, however I can't get the request/reponse to work.
我有应该动态填充的下拉菜单,但是我无法使请求/响应正常工作。 The ID of the dropdown is "start".
下拉列表的ID为“开始”。 I have an Ajax request in the frontpage file:
我在首页文件中有一个Ajax请求:
$(document).ready(function () {
$("#start").change(function(){
alert("dropdown changed");
var val = $('#start').val();
$.ajax({
type: "GET",
data: {Station_Nr : val},
url: "phpcode.php.cgi",
success: function(data){
alert(data);
}
});
});
});
and my phpfile looks like this: 和我的phpfile看起来像这样:
<?php
if(isset($_GET['Station_Nr'])) {
echo "it works";
};
?>
It tries to request from url../phpcode.php.cgi?Station_Nr=27 When I try to enter the page I get a 500 error. 它尝试从url ../ phpcode.php.cgi?Station_Nr = 27请求。当我尝试进入页面时,出现500错误。 According to chrome, the error lies in the row which starts with $.ajax.
根据chrome,错误位于以$ .ajax开头的行中。
I have included: 我包括:
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Thanks! 谢谢!
In the top of the file is #!/usr/bin/php5 located. 在文件顶部是#!/ usr / bin / php5。 Here was \\r\\n added because of Windows and the transfer method was binary.
由于Windows而在这里添加了\\ r \\ n,并且传输方法是二进制的。 The Apache server responded with an error and when replacing \\r\\n with \\n it works.
Apache服务器以错误响应,当将\\ r \\ n替换为\\ n时,它可以工作。
当您获得500错误是因为服务器不在客户端中出现问题时,请在$ .ajax中使用/phpcode.php.cgi以使用绝对路径,以防万一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.