简体   繁体   English

使用PHP和Javascript进行Ajax调用时无法获取路径

[英]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'. 我正在使用ajax调用将数据传递到服务器端,但它给我一个错误“找不到所需的路径”。 I am using code igniter for the MVC. 我正在为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: 控制器/ 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. 但是这里错误到来http://localhost/User/updateUserProfile/找不到。 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... 将您的控制器另存为UserController.php注意,第一个字母是uppercase具有updateUserProfile()函数。然后在ajax中像这样设置您的url ...

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

Hope it works. 希望它能工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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