user9758928
user9758928

Reputation:

error on ajax while using in codeigniter

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.

Upvotes: 0

Views: 53

Answers (1)

Rashid
Rashid

Reputation: 127

Missing ‘/‘ in the url.

add_express”+partnerId 

To

add_express/“+partnerId

Upvotes: 1

Related Questions