简体   繁体   中英

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. 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". I have an Ajax request in the frontpage file:

$(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:

<?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. According to chrome, the error lies in the row which starts with $.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. Here was \\r\\n added because of Windows and the transfer method was binary. The Apache server responded with an error and when replacing \\r\\n with \\n it works.

当您获得500错误是因为服务器不在客户端中出现问题时,请在$ .ajax中使用/phpcode.php.cgi以使用绝对路径,以防万一。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM