<!-- Existing value --> <input type="hidden" id="id_reclamacao" name="id_reclamacao" value=""> ...<!----------------------------------------------------------------------------------------------------->I guess an ajax code is needed to receive the value in the view, isn't it? Something like that:<!-----------------------------------------------------------------------------------------------------><script type="text/javascript"> $(function () { var serv = $('#id_reclamacao').val(); $.ajax({ url: base_url('reclamacao/get/' + serv), type: 'post', cache: false, contentType: false, processData: false, dataType: 'json', data: serv, success: function (data) { // THE WAY TO OBTAIN THE RESULT HERE IS CORRECT? $('#anexo').val(data); }, error: function(jqXHR) { bootbox.alert(jqXHR.responseText); } }); }); });</script><div class="col-xs-4 mb20"> <label for="tempo_resposta" class="field-label text-muted mb10">Download do PDF'</label> <div class="input-group"> <span class="input-group-addon"> <i class="fa fa-clock-o c-gray"></i> </span> <span class="validar"> // WHERE THE RECEIVED VALUE MUST BE USED, THIS GENERATES AN ERROR: <b><a href="<?php echo base_url($result['anexo'])?>" target="_blank">Upload do PDF relacionado</a></b></li> </span> </div></div>
Could you check and possibly give me some directions?
Thanks in advance.
PHPjQueryJSONMySQL Server
Last Comment
Eduardo Fuerte
8/22/2022 - Mon
Marco Gasi
See if I have understood: in your view you are usinh jquery to perform an Ajax call to your controller function which returns data in json format. If this is the case, then the code
is wrong: it would be correct to get the value from a DOM element with id='anexo'. Here you have no DOM element but json data, so you have to parse data array to get the required value:
success: function (data) { var anexo = data['anexo']; console.log(anexo);},
Ah ah, the funny thing is that the error couldn't help to fix the Ajax url issue: seeing the error message I would have investigate about the serv variable value and maybe I didn't notice the wrong use of the base_url() function... so the fact you had not posted the error message has been positive :)
Eduardo Fuerte
ASKER
Marco
Thank you for your dedication and competence in help!
Open in new window
is wrong: it would be correct to get the value from a DOM element with id='anexo'. Here you have no DOM element but json data, so you have to parse data array to get the required value:Open in new window
This should do the trick. I'm not sure (I can't put this in my head, don't know why!) but if this doesn't work you probably have to use JSON.parse:Open in new window