简体   繁体   中英

Can not get path while doing ajax call using PHP and Javascript

I need some help. I am passing data to server side using ajax call but its giving me an error 'The required path not found'. I am using code igniter for the MVC. Sample code below:

var url="http://localhost/User/updateUserProfile/";
$.post(url,{"form_data":dataString},function(res){
console.log("res",res);
    var getList=JSON.parse(res);
    if(getList['status']==1){
                               document.location.assign('http://oditek.in/takeme/User/userProfile');
    }else{
        alert(getList['msg']);
        return false;
    }
});

Controller/userController.php:

function updateUserProfile(){
        $form_data=$_POST['form_data'];
        parse_str($form_data,$data);
        if(isset($data) && !empty($data)){
            $user_id=strip_tags(trim($data['user_id']));
            $user_name=strip_tags(trim($data['user_name']));
            $user_email=strip_tags(trim($data['user_email']));
            $user_mobile=strip_tags(trim($data['user_mobile']));
            $user_emergency_contact=strip_tags(trim($data['user_emergency_contact']));
            $user_address=strip_tags(trim($data['user_address']));
            $user_gender=strip_tags(trim($data['user_gender']));
            $values = array($user_name,$user_email,$user_mobile,$user_emergency_contact,$user_address,$user_gender);
            $columns = array("name","email","mobile","emergency","address","gender");
            $condn="pro_Id='".prepare_param($user_id)."'";
            $tablename="tm_user_list";
            $id=db_update($tablename,$fields,$values,$condn);
            if($id !=false){
                $data=array("status"=>1,"msg"=>"Updated Successfully");
            }else{
                $data=array("status"=>1,"msg"=>"Could not Updated");
            }
        }
        echo json_encode($data);
    }

I am calling the above function for sending data to server side. But here the error is coming http://localhost/User/updateUserProfile/ is not found. Please help me to resolve this issue.

Save your controller as UserController.php .Notice that the first letter is in uppercase having function updateUserProfile() .Then in ajax set your url like this...

var url="http://localhost/User/UserController/updateUserProfile/";

Hope it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM