drgd73844 2017-02-22 18:59
浏览 133

未定义的变量使用Ajax之后

I am doing a small web application. The purpose of this application is storing data to my database. Here is my application process:

First ,the user will upload they file to my web. Here is how file format looks like.

The test.txt will record that each companys sell different items on the date.

test.txt

companyA
date price name
02/12 9.99 name1
...   ... ...
12/01 996.00 name100
companyB
date price name
02/12 9.99 name2
...   ...
12/01 956.00 name200
companyC
date price name
02/12 4.99 name5
...   ...
12/01 996.00 name200
companyD
date price name
02/12 59.99 name1
...   ...
12/01 96.00 name400

Second step: Once use uploaded test.txt. I will display companyA,companyB,companyC and companyD to front-end.(I use <div id="company_result0" style="color:#0A0A0A"></div>).When I display company ,i use radio button for each company name.

    $('#company_result0').append($('<input type="radio" name="companyName" value="' + (key+1) + '" > ' + value + '</input><br />'));

Third step: Let use choose which company information they want to store.

index.html

<form name="uploadform" id="uploadform"  >
<input id="file_browse" type="file" class="btn btn-default text-center defbtntext"  name="fileToUpload">
 </form>
<form class="data-display" id="data-display" name ="data-display">
<div id="company_result0"  style="color:#0A0A0A"></div>
</form>

ajax.js

function getUploadFile() {
        $('#uploadform').on('change', function(e) {
              e.preventDefault();
              var formData = new FormData($(this)[0]);
              $.ajax({
                  type : "POST",
                  url : "findName.php",
                  data : formData,
                  processData: false,
                  contentType: false,
                  success: function (result) {

            var entry = JSON.parse(result);
            $.each(entry ,function(key,value) {
            $('#company_result0').append((key+1));
            $('#company_result0').append(": ");
            $('#company_result0').append($('<input type="radio" name="companyName" value="' + (key+1) + '" > ' + value + '</input><br />'));


        });
 ('#company_result0').append($('<input type="submit" id="submitCompanyName" name="submitCompanyName"</input><br />'));
                 }

              });
        });
}

findName.php

$tempfile = $_FILES ['fileToUpload'] ['tmp_name'];
$fileInfo = new getFileInfo ( $tempfile );
$fileInfo->findcompanyname ();
$fileInfo->sendcompanynametofront ();//send each company name to front.

/**company names will display in #company_result0.
*How can I to get value from #company_result0?
*Here is my code for get value, but it is not work.
*it will show me undefined variable :companyName error.
*/

if ($_SERVER ["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['companyName'])) {
        $companyName=$_POST['companyName'];

    }
}

getFileInfo.php

function sendcompanynametofront() {
    echo json_encode ( companyNameArray );
}

My question is How can I to get value from #company_result0.

When I click submit button in #company_result0 ,it will give the error which is undefined variable :companyName.

Please let me know if there are any misunderstanding.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么