0

Ajax is not working while using in CodeIgniter. The alert message inside the script is working well but the controller function is not getting the call to perform.

View part

<div class="col-md-6 col-sm-6 col-xs-12"> <a class="buttons" onclick="updateExpress(<?php echo $lp->User_Id; ?>)" id="<?php echo $lp->User_Id; ?>" href="javascript:;"> <span class="button-icon"><i class="far fa-heart"></i> </span>Express your interest</a> </div> 

script added in the view part is:

<script> function updateExpress(partnerId){\ $.ajax({ url:"<?php echo base_url() ?>index.php/Home/add_express"+partnerId }); alert("Expressed interest at Profile ID M"+partnerId); } </script> 

The controller part is mentioned below:

public function add_express() { $partnerExp=$this->uri->segment(3); $user=$_SESSION['userID']; $datetoday=date("d-m-Y"); $data=array( 'NotificationTo' => $partnerExp, 'NotificationFrom' => $user, 'Notification_Id' => '6', 'date' => $datetoday, 'Is_read' => '0' ); $data['addresult']=$this->action_data->add_express($data); } 

This function is working while calling this controller function separately. But when it is trying to call using ajax it doesn't work.

3
  • 1
    Missing / ? Change - add_express"+partnerId - to -add_express/"+partnerId Commented May 8, 2018 at 14:18
  • You may wanna use site_url() there rather than base_url() so you won't have to type index.php at the same time. >> Reference << Commented May 8, 2018 at 14:21
  • 1
    Thanks a lot. I was searching for this error this whole day... thank you so much. It exactly works now... @Mr.Blue Commented May 8, 2018 at 14:23

1 Answer 1

1

Missing ‘/‘ in the url.

add_express”+partnerId 

To

add_express/“+partnerId 
Sign up to request clarification or add additional context in comments.

Comments