0

我正在开发一个 JQuery 脚本,该脚本基本上根据输入从选择框中提取数据,并根据选择隐藏/显示变量(当前正在测试数据)

就 JQUERY 刷新和更新值而言,我的脚本可以正常工作。我目前的问题是我似乎无法让变量通过以用于其他步骤。

这是我到目前为止所拥有的。现在我在将变量传递到下一步时遇到问题。

这是 JQuery/HTML 部分:

<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 form is submitted to PHP Call
  $('#crs').submit(function() {
    // Get form data ready for PHP Call
    var Sphone = $('#crs #Sphone').val();
    var Schat = $('#crs #Schat').val();
    var Smeet = $('#crs #Smeet').val();
    var Sremo = $('#crs #Sremo').val();
    var Sport = $('#crs #Sport').val();
    var Smail = $('#crs #Smail').val();
    var Svoic = $('#crs #Svoic').val();
    var Sfax = $('#crs #Sfax').val();


    // put form data in a JSON format that will be sent to the PHP File
    var data_json = {'Sphone':Sphone, 'Schat':Schat, 'Smeet':Smeet, 'Sremo':Sremo, 'Sport':Sport, 'Smail':Smail, 'Svoic':Svoic, 'Sfax':Sfax};

    // Set AJAX method
    // If succeeds, goes to the  next step
    $.ajax({
      type: 'post',
      url: 'script.php',
      data: data_json,
      beforeSend: function() {
        // before send the request, displays a "Loading..." messaj in the element where the server response will be placed
        $('#resp').html('Loading...');
      },
      timeout: 10000,        // sets timeout for the request (10 seconds)
      error: function(xhr, status, error) { alert('Error: '+ xhr.status+ ' - '+ error); },
      success: function(response) { $('#resp').html(response); }
    });

    return false;      // required to not open the page when form is submited
  });
});
--></script>
</head>
<body>
<div id="resp"></div>
<h4>Fill the form:</h4>
<form action="script.php" method="post" id="crs">
Phone Support: <select name="Sphone" id="Sphone">
  <option value="Pen1">Yes</option>
  <option value="">No</option>
   </select><br />

Live Chat Support: <select name="Schat" id="Schat">
  <option value="Pen2">Yes</option>
  <option value="">No</option>
   </select><br />

Live Meeting: <select name="Smeet" id="Smeet">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />
Remote Support: <select name="Sremo" id="Sremo">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />
Ticket By Portal: <select name="Sport" id="Sport">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Email: <select name="Smail" id="Smail">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Voicemail: <select name="Svoic" id="Svoic">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

Ticket By Fax: <select name="Sfax" id="Sfax">
  <option value="Pen3">Yes</option>
  <option value="">No</option>
   </select><br />

 <input type="submit" value="submit" />
</form>

这是 PHP 部分。

if(isset($_POST['Sphone']) && isset($_POST['Schat']) && isset($_POST['Smeet']) && isset($_POST['Sremo']) && isset($_POST['Sport']) && isset($_POST['Smail']) && isset($_POST['Svoic']) && isset($_POST['Sfax'])) {
  $_POST = array_map("strip_tags", $_POST);       // Gets rid of tags in POST Call

  // get data
  $Sphone = $_POST['Sphone'];
  $Schat = $_POST['Schat'];
  $Smeet = $_POST['Smeet'];
  $Sremo = $_POST['Sremo'];
  $Sport = $_POST['Sport'];
  $Smail = $_POST['Smail'];
  $Svoic = $_POST['Svoic'];
  $Sfax = $_POST['Sfax'];

// Define Full Output of variable   
  $arrow ='<textarea name="supportArticle" cols="160" rows="15" wrap="virtual">'.$Sphone.' <br> '.$Schat.' <br> '.$Smeet.' <br> '.$Sremo.' <br> '.$Sport.' <br> '.$Smail.' <br> '.$Svoic.' <br> '.$Sfax.'</textarea>';
   function passVariable($arrow)
    {
    return $arrow or die(mysql_error());
    }
  }
echo $arrow; 

我确实有更多的代码,但这只是数据库连接等。

这可以很好地更改变量。现在我有 Pen 1、Pen 2 等......作为占位符(中间有一个中断)。

我想将所有这些保存在一个文件中。我用一个名为 $arrow 的变量对此进行了测试,它不会回显这个变量(也向它添加了一个 DIE 错误,然后将其删除) - 任何接受者?

4

0 回答 0