选择 OnChange 更改 PHP 变量

Selection OnChange change PHP Variable

你好 Whosebug 人。

我需要你的帮助。我有这个代码:

<select name="type" onChange="idk?" class="form-control">
<option value="H">Week 51</option>
<option value="V">Week 52</option>
</select>

如果用户更改周,我想更改文件获取内容 :s

$Week = "";
echo file_get_contents('http://rooster.farelcollege.nl/'.$Week.'/c/c00050.htm');

谢谢!

来自荷兰的问候=)

您可以向 "file_get_contents" url 发送 Ajax 请求。 这就是我正在使用的并且工作正常:)

<select name="type" class="form-control">
    <option value="H">Week 51</option>
    <option value="V">Week 52</option>
</select>

$(document).ready(function() {
  $( ".form-control" ).change(function() {
    $.ajax({
        data: {
            // You are not sending any post variables right? Then leave this empty :-) otherwise use it as array 'var1': 'value', 'var2': 'value2' ...
        },
        url: 'http://rooster.farelcollege.nl/'+$(this).val()+'/c/c00050.htm',
        method: 'POST',
        success: function(msg) {
            alert(msg); // Optional, show text that was given by URL, can be removed
        }
    });
  });   
}); 

jquery.com/jquery.ajax