简体   繁体   English

将JS输出到php中的post方法

[英]Output JS into post method in php

I want to send an ID (using POST method) from a .js file into a form in php. 我想将.js文件中的ID(使用POST方法)发送到php中的表单中。

The code in my .js file is 我的.js文件中的代码是

function PMID(pmid) {
    var result;
    $.ajax({
        async: false,
        type: 'POST',
        url: '../controller/acmg_controller.php',
        dataType: 'json',
        data: {
            pmid: pmid 
        },
        success: function(data1) {
            result = data1;


        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("parse1 abstract");
        }
    });
    return result;
}

The code in my php file is: 我的php文件中的代码是:

date_default_timezone_set("America/New_York");
$date= date('20y-m-d');
$result = $_POST['ACMG'];
$result_explode = explode('|', $result);
$data_array = array('ACMG Category' => $result_explode[0],
                    'ACMG ID' => $result_explode[1], 
                    'Evidence Support' => $_POST["Evidence"], 
                    'Summary' => $_POST["text"], 
                    'Source' => $_POST["source"], 
                    'Date'=> $date);

$data_array_jsencode = json_encode($data_array);
echo $data_array_jsencode;
$pmid = $_POST['data'];
print_r($pmid);

The output after submitting the form should have the 'PMID' which is sent from the .js file. 提交表单后的输出应具有从.js文件发送的'PMID'。 However, I cant get the PMID from the php file . 但是,我无法从php文件中获取PMID。

First of Pass All $_POST Parameter from JS which you have used in PHP file. 首先传递您在PHP文件中使用的来自JS的所有$_POST参数。 Change into your php file 更改为您的php文件

$pmid = $_POST['data'];
print_r($pmid);

TO

$pmid = $_POST['pmid'];
print_r($pmid);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM