Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-AJAX load()方法如何添加2个多变量_Jquery_Ajax_Methods_Load - Fatal编程技术网

jQuery-AJAX load()方法如何添加2个多变量

jQuery-AJAX load()方法如何添加2个多变量,jquery,ajax,methods,load,Jquery,Ajax,Methods,Load,我有这个密码。我需要再添加一个分季变量。如何添加更多变量?我正在谷歌搜索,但没有结果。 如果你能帮助我,谢谢你 <?php echo"<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script> <script type='text/javascript'><!-- $(document)

我有这个密码。我需要再添加一个分季变量。如何添加更多变量?我正在谷歌搜索,但没有结果。 如果你能帮助我,谢谢你

<?php
echo"<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
<script type='text/javascript'><!--
$(document).ready(function() {
  // when the user submit a form
  $('form').submit(function() {
    var url = $(this).attr('action');       // gets the url from 'action' attribute of the current form

    // define data to be send to PHP
    // with the key 'pag' and the value selected in the select list (with id='pag')
    var data = 'season='+ $('#season').val();

    // adds a 'loading...' notification, load the content from url (passing the data)
    // and place it into the tag with id='content'
    $('#content').html('<h4>Loading...</h4>').load(url, data);
    return false;
  });
});
--></script>";
echo"<div id='content'>Default</div>
<form action='script.php' method='get'>
 Select course:
 <select name='season' id='season'>
  <option value='season'>season</option>
  <option value='php'>PHP</option>
  <option value='ajax'>Ajax</option>
 </select> 

<select name='sub_season' id='sub_season'>
  <option value='sub_season'>sub_season</option>
  <option value='php'>PHP</option>
  <option value='ajax'>Ajax</option>
 </select>
 <input type='submit' id='submit' value='Submit' />
</form>";
?>

您可以选择通过GET或POST发送数据

// send multiple vars via post
var data_post = {};
data_post.season = $('#season').val();
data_post.sub_season = $('#sub_season').val();

// send multiple vars via get
var data_get = 'season='+$('#season').val()+'&sub_season='+$('#sub_season').val();
并在
script.php
中捕获变量,如下所示:

<?PHP
    if(isset($_POST['season']))
        echo '<h1>'.$_POST['season'].' [post]</h1>';
    if(isset($_POST['sub_season']))
        echo '<h1>'.$_POST['sub_season'].' [post]</h1>';

    if(isset($_GET['season']))
        echo '<h1>'.$_GET['season'].' [get]</h1>';
    if(isset($_GET['sub_season']))
        echo '<h1>'.$_GET['sub_season'].' [get]</h1>';
?>

为什么要这样呈现静态HTML???
// via GET
var data_get = 'season='+$('#season').val(); 
$('#sub_season :selected').each(function(){ 
  data_get += '&sub_season[]='+ $(this).val(); 
});

// via POST
var data_post = {};
data_post.season = $('#season').val(); 
data_post.sub_season = [];
$('#sub_season :selected').each(function(){ 
  data_post.sub_season.push($(this).val()); 
});