Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用JSON渗透隐藏字段_Javascript_Php_Json_Laravel 5.2 - Fatal编程技术网

Javascript 使用JSON渗透隐藏字段

Javascript 使用JSON渗透隐藏字段,javascript,php,json,laravel-5.2,Javascript,Php,Json,Laravel 5.2,使用Laravel5.2.*和纯JavaScript // opening form, label and stuff <input type="text" name="selectionAutocomplete" id="selectionAutocomplete" list="jobsList"> <datalist name="jobsList"> // op

使用Laravel5.2.*和纯JavaScript

// opening form, label and stuff

<input type="text" name="selectionAutocomplete" id="selectionAutocomplete" list="jobsList">
<datalist name="jobsList"> 
  // options appended here
  // elements look like this
  // <option value="Purchase - New Mouse for Deskjob"></option>
</datalist>

<input type="hidden" name="sectionId" id="sectionId">
<input type="hidden" name="jobId" id="jobId">
<input type="hidden" name="typeId" id="typeId">
<input type="hidden" name="categoryId" id="categoryId">
TL;DR

  • 我需要帮助访问JSON参数,以在一些隐藏字段中填充value属性

  • 以及从JSON中获取“有用信息”值并渗透到模式中以向用户提供信息的方法

  • 我对jQuery包不太感兴趣,因为这个项目已经有20多个包了

我对Laravel和JSON的使用都相当陌生,所以我遇到了一个问题

我有一个带有表单的页面,我有几个参数要填写,但最重要的是我设置为自动填写的隐藏字段,因为从某种程度上说,这些是用户不知道的参数

当用户提交表单时,参数被插入到我数据库中的表“
jobsCreated
”中,该表基本上是一种跟踪企业正在做的每一件小事(购买、销售、要求新设备、租用、创建帐户以进入系统等)的方法。该表在某种程度上是一团糟的(该表有20多列,其中11列是外键),它使用复合键生成“
createdJobID

此表中的大多数外键来自另一个名为“
jobsList
”的表。我已经创建了一个JSON文件,其中包含该表的所有参数和元素。像这样:

jobs.json

{
    "enterpriseID":2,
    "sectionID":1,
    "jobID":7,
    "jobDescription":"Purchase - New Mouse for Deskjob",
    "usefulInformation":"Please specify the value of the equipment",
    "urgencyLevel":"normal",
    "atendantID":0,
    "isPublic":1,
    "searchEqualFiles":0,
    "formType":21
},
{
    "enterpriseID":2,
    "sectionID":1,
    "jobID":8,
    "jobDescription":"Purchase - New Laptop/Desktop to Deskjob",
    "usefulInformation":"Inform the type of equipment and value",
    "urgencyLevel":"normal",
    "atendantID":0,
    "isPublic":1,
    "searchEqualFiles":0,
    "formType":21
},
[ it goes on for another 260++ entries, following this model]
系统在表单中要求的另一件事是列出JSON中所有作业的自动完成ish字段。我提出了一个JavaScript代码,它可以渗透到带有多个
选项
字段的
数据列表中,如下所示:

completeForm.js

// hidden inputs
var sectionId = document.getElementById('sectionId');
var jobId = document.getElementById('jobId');
var jobTypeId = document.getElementById('typeId');
var categoryId = document.getElementById('categoryId');
var selectionOption = document.getElementsByName('selectJob');
// input autocomplete e dataList
var input = document.getElementById('selectionAutocomplete');
var dataList = document.getElementById('jobsList');
var request = new XMLHttpRequest();


request.onreadystatechange = function(response)
{
  if(request.readyState === 4)
  {
    if(request.status === 200)
    {
      // important bit, bolding it
      var jsonOptions = JSON.parse(request.responseText);
      for(var i = 0; i < jsonOptions.length; i++)
      {
        var option = document.createElement('option');
        option.value = jsonOptions[i].jobDescription;
        dataList.appendChild(option);
      }
      
      input.placeholder = "Type the name of a job";
    }
    else
    {
      input.placeholder = "No jobs found";
    }
  }
};

input.placeholder = "Loading jobs";

request.open('GET', '{{{ url('storage/app/jobs.json') }}}', true);
request.send();
在隐藏字段中,我想将
value
属性设置为JSON中存在的相同属性(如果存在)。 因此,例如,如果我选中选项
“Purchase-New Mouse for Deskjob”
,我希望访问此特定选项的JSON位置,并在隐藏字段中渗透
属性,并触发包含“
usefulInformation
”字符串的模式

欢迎任何类型的帮助。先谢谢你