0

この jQuery スクリプトは null を返しています。選択したオプションに他の構文を使用してみましたが、以下のとおりです。

スクリプトが正しく動作し、Excel ファイルをダウンロードできるようになりました。ただし、ID は (選択したオプションを介して) 正しく設定されていないため、「0」として解析されます。

<script>
//When Page Loads....
$(document).ready(function(){

  $('#dropdown').change(function(){
    // Call the function to handle the AJAX.
    // Pass the value of the text box to the function.
    sendValue($(this).val());   
  }); 
});

// Function to handle ajax.
function sendValue(str){
  // post(file, data, callback, type); (only "file" is required)
  $.post(
    "scripts/export_to_excel/index.php", //Ajax file
    { sendValue: str },  // create an object will all values
    //function that is called when server returns a value.
    function(data){
      $('#linkDiv').html(data.returnValue);
    }, 
    //How you want the data formatted when it is returned from the server.
    "json"
  );
}
</script>

HTML を選択

<p>Select event for export to Excel:</p>
<p>
  <select name="eventIDExport" id="dropdown"> 
    <option value=0> 
    <?=$options?> 
  </select>
</p>
<?php var_dump($_POST['eventIDExport']); ?>
<div id="linkDiv"></div>

レンダリングされたマークアップ

<p>Select event for export to Excel:</p>
<p>
  <select name="eventIDExport" id="dropdown"> 
    <option value=0> 
    <option value="1">BIG event</option>
    <option value="54">2013 Network Conference</option>
  </select>
</p>
NULL
<div id="linkDiv"></div>

Ajax リクエストを処理するための index.php のコードの一部 - これが null 値をトリガーしていると思いますか?

if (isset($_POST['eventIDExport']))
{
$eventIDExport = $_POST['eventIDExport'];
}else{
$eventIDExport = "";    
}
4

1 に答える 1

1

sendValuePOSTして設定されているかどうかを確認するのはなぜeventIDExportですか?

$.post("scripts/export_to_excel/index.php", {
    sendValue: str
    ^^^^^^^^^

if (isset($_POST['eventIDExport']))
                  ^^^^^^^^^^^^^

コードは次のようになります。

if(isset($_POST['sendValue']))
{
    $eventIDExport = $_POST['sendValue'];
} else {
    $eventIDExport = "";
}

また

$.post("scripts/export_to_excel/index.php", {
    eventIDExport: str
于 2012-07-25T20:29:16.117 に答える