javascript - ajax reading/getting variable sometimes cannot get the exact variable with codeigniter -


i having problem in ajax or don't know if problem ajax. have ajax code value label , concat in fresh data database. everytime refresh page, outputs different. works fine, , doesn't.

i having trouble in part :

else {               value = value + "-"+init;               $('#checkid').text(value);               $("#checkid").css('visibility','visible');             } 

sometimes outputs 1-0 , output became -0. thinking of var value = $('#clinicid').html(); cannot concat -0 1 of output 1-0 came value variable

here ajax full code :

function getcheckupid() {  var init = 0; var value = $('#clinicid').html();    $.ajax ({     url: siteurl+"myclinic/getcheckid",     type: "get",     datatype: "json",     success: function(data) {         if(data.length>0) {            $('#checkid').text(data[0]['check_up_id']);           $("#checkid").css('visibility','visible');         }         else {           value = value + "-"+init;           $('#checkid').text(value);           $("#checkid").css('visibility','visible');         }     }   })  } 

my document ready code:

$(document).ready(function() {   get_clinicid();   show_patients();   checkupme(); }); 

where checkupme() function got nested getcheckupid() runtime

i suggested way data in #clinicid can use

when refresh page, insert #clinicid like:

<span id="clinicid" data-value="1-0"><span> or whatever data wanna input.

then in getcheckupid function you'll call:

function getcheckupid() {   var init = 0;   var value = $('#clinicid').attr("data-value");   // code ajax } 

if still have problem, please check echo when page generated. maybe there're not value print.

hope help.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -