Проверенное значение jquery radiobutton показывает неопределенное - PullRequest
0 голосов
/ 20 сентября 2019

Я создал страницу для загрузки файла и обработки его с помощью Ajaxupload.Я хочу отправить еще данные вместе с файлом.В этом случае информация о высоте.Эта информация должна быть получена от выбранного переключателя с именем "ht".Я попытался предупредить его значение «alert (radioButton)», чтобы убедиться, что значение передается.Но я получаю сообщение «неопределено».Ниже приведен сценарий.

<script type="text/javascript" >
    $(document).ready(function(){
        //$(function(){
            var radioButton =$("[name='ht']:checked").val();
            var btnUpload=$('#upload');

            var status=$('#status');
            new AjaxUpload(btnUpload, {

                action: 'upload-file.php',
                name: 'uploadfile',
                data: 'height='+radioButton +'',
                onSubmit: function(file, ext){
                     if (! (ext && /^(xls|xlsx)$/.test(ext))){ 
                        // extension is not allowed 
                        status.html('Only xls, xlsx files are allowed');
                        return false;
                    }
                    this.setData({ height: radioButton }); 
                    alert(radioButton);
                    //status.text('Uploading...');
                     jQuery("#plot").html("<img src='images/ajax-loader.gif'/>");
                },
                onComplete: function(file, response){
                    //On completion clear the status
                    jQuery("#plot").html("");
                    status.text('');
                    //Add uploaded file to list
                    //alert(response);

                        jQuery("#plot").html(response);
                        //.addClass('success')

                }
            });

        });
    </script>

html для страницы:

div id="content">
 <div id="menu"></div>
 </br> </br>
<h3 class="title"> UPLOAD WIND DATA</h3>

<!-- submenu tag begins-->
<div class="report_upload">
<DIV class="desc"></DIV>
<br/>
<br/>
<div>
Kindly ensure that you are uploading .xlsx files (Office 2007) . It should have 8 columns, and data from second row onwards. First row can be used for give headings, if you wish to do so. Column order for data is date (in YYYY-MM-DD) , time (24 hr, hh:mm:ss format), 10m direction (in degree,)10m speed (m/s) 60m direction (in degree,)60m speed (m/s) 100m direction (in degree,)100m speed (m/s). There is no data validation employed. Hence please ensure that the uploaded file contains valid data.
</div>
<br/>
Height<input name="ht" type="radio" value="10" />10m<input name="ht" type="radio" value="60" />60m<input name="ht" type="radio" value="100" >100m 

<div id="upload" ><span>Upload File<span></div><div id="plot"><span id="status" ></span></div>

        <ul id="files" ></ul>
</div>
<!--submenu ends-->


</div>
<!--end content -->
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...