Convert query to JQuery and ajax

1

Hi, I have an MVC project and I'm using a server's database. In the project I do the consultations with javascript, and it happens that I have an input to select the date in a calendar and an option to select the name of a user already loaded from the database.

My question is how to show the other fields of the user (in the div called "data") according to the name and date selected by clicking on the button see ...

In other words, how to translate:     "Select * from table where user=" + inputUser + "and date=" + inputdate + "'"; in javascript language and / or ajax. I really do not have much idea here I leave my html code:

  <div class="col-md-5">
  <select class="form-control" name="IdGestor">
  <option></option>
  @{
  if (Model.UsersList != null)
  {
  foreach (Users users in Model.UsersList)
  {
  <option value="@gestores.id">@users.Nombre</option>
  }
  }
  else
  {
  <option value="0"> No hay usuarios </option>
  }
  }
  </select>
  </div>

  <div class="col-md-5">
  <input type="date" class="form-control" id="Fecha" placeholder="Fecha" required pattern="[0-9]{2}-[0-9]{2}-[0-9]{4}" />
  <span class="validity"></span>
  </div>
  <div class="col-md-2">
  <a href="#" class="btn btn-link dropdown-toggle" id="ver" style="font-size:20px" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" title="Ver">
 <span class="fa fa-search">Ver</span>
 </a>
 </div>

 
 <div id="datos"></div>
    
asked by Geek 18.10.2018 в 18:56
source

2 answers

0

I did not understand your question well, if I select a user of the select, I have to show the other data within the data not? You have to go through the arrangement with a for similar to the one you have at the beginning:

for(user as users){
   <li><?php echo user->nombre; ?></li>
   <li><?php echo user->apellido; ?></li>
}

Something similar to this clear in users stored all the record you get from the query.

    
answered by 19.10.2018 в 00:35
0

To do this kind of thing you usually have to build a REST endpoint that receives the user_id and the date; and return the information you need in some format, it can be xml, json or even html ready to insert directly into your div #datos. It is recommended that you use json and build the html with javascript and then insert it into your div #datos.

Another more sloppy but simple solution, in case it is an exercise only, would be to load absolutely all the information of all the users in the html in the form of divs that have as id the user_id and the date. And you have all hidden. For example:

<div id="user_123_20181017" style="display: none">...</div>
<div id="user_123_20181018" style="display: none">...</div>
<div id="user_456_20181018" style="display: none">...</div>
<div id="user_789_20181018" style="display: none">...</div>

And that in the onclick event you decide to show the corresponding div.

In any case, the solution is not trivial and it would be difficult to translate it efficiently here.

    
answered by 19.10.2018 в 02:12