2016-05-23 5 views
2

ich ein Datumsbereich Formularfeld tue, hier console.log (fname) bedeutet i alle Werte, und ich möchte in einer Tabelle td diesen Wert anhängen, ich versuche, wie dieser Methode, aber es nicht funktioniert, wie ich diesen Wert in tdWie Sie den Wert in der Tabelle anhängen

 <div class="input-group"> 
 
    <div class="input-group-addon"> 
 
     <i class="fa fa-calendar"></i> 
 
    </div> 
 
    <input type="text" class="form-control pull-right" id="reservation"> 
 
</div> 
 

 
<script type="text/javascript"> 
 
    $(document).ready(function() { 
 
     $("#reservation").on("change", function() { 
 
      var reservation = $(this).val(); 
 
      $.ajax({ 
 
       type: 'post', 
 
       url: 'date-range.php', 
 
       data: { 
 
        logindate: reservation, 
 
       }, 
 
       success: function(data) { 
 
        var res = jQuery.parseJSON(data); // convert the json 
 
        console.log(res); 
 
        if (res['status'] == "success") { 
 

 
         var htmlString = ''; 
 

 
         $.each(res['data'], function(key, value) { 
 

 
          htmlString += '<tr>'; 
 
          var ssm_id = value.ssm_id; // here i got ssmid 
 
          htmlString += '<td>' + value.ssm_id + '</td>'; 
 
          $.ajax({ 
 
           type: 'post', 
 
           url: 'config/functions.php', 
 
           data: { 
 
            ssm_id: ssm_id, 
 
           }, 
 
           success: function(fname) { 
 
            console.log(fname); //here i got all names 
 
            // kani 
 
            // mahi 
 
            // kogila like this ans it will come console.log(fname),i want appent this value in hmlString+='<td>'+fname+'</td>'; 
 
            htmlString += '<td>' + fname + '</td>'; // here value is not appending,nothing is happen 
 
           } 
 
          }); 
 

 
          htmlString += '<td>' + 'Muthuraja' + '</td>'; 
 
          htmlString += '<td>' + '20-05-2016' + '</td>'; 
 
          htmlString += '<td>' + 'status' + '</td>'; 
 
          htmlString += '<td>' + value.source + '</td>'; 
 
          htmlString += '<td>' + "<span style='color:green'>View Profile</span>" + '</td>'; 
 

 
          htmlString += '</tr>'; 
 
         }); 
 
         $('#datatable-editable > tbody').empty().append(htmlString); 
 
        } else { 
 
         $('#datatable-editable > tbody').empty().append("<center style='height:100px;padding-top:36px;color:red;font-size:17px;'><b>No matching records found</b></center>"); 
 
        } 
 
       } 
 
      }); 
 
     }); 
 
    }); 
 
</script> 
 

 

 
functions.php 
 

 
<?php 
 
    $ssm_id = $_POST['ssm_id']; 
 
    if(!empty($ssm_id)){ 
 
    echo firstname($ssm_id); 
 
    } 
 

 
    function firstname($id) 
 
    \t { 
 
    \t \t $f="SELECT firstname FROM register WHERE matri_id='$id'"; 
 
    \t \t $rr=mysql_query($f); 
 
    \t \t while($row=mysql_fetch_array($rr)) 
 
    \t \t \t { 
 
    \t \t \t \t $firstname = $row['firstname']; 
 
    \t \t \t } 
 
    \t \t \t return $firstname; 
 
    \t } 
 

 
    ?>

+0

Ihre 'ajax' innen' success' Betrieb des ersten 'ajax' funktioniert nicht richtig, wie Sie mit Ihrer Arbeit fort Werte' htmlString' anhängt, ohne für die Fertigstellung der 'ajax' innen' success' zu warten –

+0

Wie kann man das ???? möglich bedeutet update Ihre Antwort –

+0

Warum verwenden Sie nicht Join statt zwei Ajax Anruf – Vinie

Antwort

1

gerade das Schreiben des success Teil anhängen können. Ich hoffe, Sie werden dies zur Arbeitsstruktur bringen.

success: function(data) { 
    var res = jQuery.parseJSON(data); // convert the json 
    console.log(res); 
    if (res['status'] == "success") { 
    $('#datatable-editable > tbody').empty();//emtpy tbody at the begining 
    $.each(res['data'], function(key, value) { 
     var htmlString = ''; //Place declaration inside each 
     htmlString += '<tr>'; 
     var ssm_id = value.ssm_id; // here i got ssmid 
     htmlString += '<td>' + value.ssm_id + '</td>'; 
     $.ajax({ 
     type: 'post', 
     url: 'config/functions.php', 
     data: { 
      ssm_id: ssm_id, 
     }, 
     success: function(fname) { 
      htmlString += '<td>' + fname + '</td>'; 
      //move the whole set inside success of this ajax 
      htmlString += '<td>' + 'Muthuraja' + '</td>'; 
      htmlString += '<td>' + '20-05-2016' + '</td>'; 
      htmlString += '<td>' + 'status' + '</td>'; 
      htmlString += '<td>' + value.source + '</td>'; 
      htmlString += '<td>' + "<span style='color:green'>View Profile</span>" + '</td>'; 
      htmlString += '</tr>'; 
      $('#datatable-editable > tbody').append(htmlString); 
     } 
     }); 

    }); 

    } 
} 
+0

Wow netter Mann, jetzt habe ich danke @@ Guruprasad Rao –

+0

Jederzeit .. Happy Coding .. –

+0

Ich habe noch einen Zweifel, wie man die eine mehr Funktion in diesem code.isteed von dieser htmlString + = '' + 'Muthuraja' + ''; Ich möchte die Funktion , wie kann man hier tun –

Verwandte Themen