monim20 Posted January 18, 2013 Share Posted January 18, 2013 I have this function which uses ajax ,but this function is not working ,I tried a lot ,but not able to figure out where is the problem ,I am trying to create alert if user inserts duplicate entry in database using check-box selection <script> function func(e,eid,emprid) { if(document.getElementById(e).checked){ var dataString = 'eid='+eid +'&emprid='+emprid ; $.ajax({ type:"POST", url: "mylistcheck.php", data: dataString, success: function(result){ if(result!='0') { modal.open({content: "<span style=\"color:red\" ><h2>You have already selected candidate </h2></span>"}); document.getElementById(e).checked=false; } } }); } } </script> mylistcheck.php file <?php require_once("includes/session.php"); ?> <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php $eid=$_POST['eid']; echo "eid".$eid; $emprid=$_POST['emprid']; echo "rid".$emprid; $sqlchecklist="SELECT * FROM selected_candidate WHERE eid='{$eid}' AND rid='{$emprid}' "; $checklistres=mysql_query($sqlchecklist); $list_check=mysql_num_rows($checklistres); echo "numrows listcheck".$list_check; if($list_check>0) { echo "1"; } else { echo "0"; } ?> check-box code echo "<td><input id=\"select_candi{$i}\" onclick=\"javascript:func(this.id,{$data_set['eid']},{$emprid})\" type=\"checkbox\" name=\"check_candi[]\" value=\"{$data_set['eid']},{$emprid}\"/></td>"; Link to comment https://forums.phpfreaks.com/topic/273303-ajax-code-not-working/ Share on other sites More sharing options...
Muddy_Funster Posted January 18, 2013 Share Posted January 18, 2013 could possably be a white space issue - try trimming the result variable before checking it Link to comment https://forums.phpfreaks.com/topic/273303-ajax-code-not-working/#findComment-1406633 Share on other sites More sharing options...
monim20 Posted January 18, 2013 Author Share Posted January 18, 2013 can you please tell me syntactically how can i trim it as i am new to php Link to comment https://forums.phpfreaks.com/topic/273303-ajax-code-not-working/#findComment-1406634 Share on other sites More sharing options...
Muddy_Funster Posted January 18, 2013 Share Posted January 18, 2013 you would o the trim in the Javascript : success: function (result){ var myResult = trim(result); alert(myResult); //<---test to see what's actualy coming back from the php page, delete this line when all is working modal.......//<<the rest of your code Link to comment https://forums.phpfreaks.com/topic/273303-ajax-code-not-working/#findComment-1406635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.