My complete script is as follows
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<script type="text/javascript">
$(window).on('load',function(){
$('#myModal').modal('show');
});
</script>
<script>
$( document ).ready(function () {
$("#vote").click(function (e) {
var poll_id = $('input[name=pollID]', '#myForm').val();
var poll_option_id = $('input[name=voteOpt]:checked', '#myForm').val() ;
//alert(poll_id + "AND" + poll_option_id);
$.ajax({
type: "POST",
url: "http://localhost/poll/index.php/form/poll",
data: {poll_id: poll_id, poll_option_id: poll_option_id},
dataType: "json",
success: function(data) {
alert(data);
}, error: function() {
alert("ERROR");
}
});
});
});
</script>
And I have the following inside poll function in form controller
public function poll() {
$pollid = $this->input->post('pollID');
$voteData = array(
'poll_id' => $pollid,
'poll_option_id' => $this->input->post('voteOpt')
);
$voteSubmit = $this->modal->vote($voteData);
if($voteSubmit){
echo 'Your Vote Has Been Submitted successfully.';
}else{
echo 'You Had Already Voted.';
}
}
Now the thing is that, modal is executing perfectly on page load. But ajax is not working neither success part is executing nor error. Also on uncommenting the alert before ajax, correct values are alerted. I cannot figure the error. Please help
