我使用以下代码将值发送到服务器(PHP脚本)以相应地执行操作。
JS代码:
$.ajax({
type: "POST",
url: "/application/helpers/fb_login_assist.php",
data: {fbname: name,
fbid: id,
fbemail: email,
fbgender: gender,
fbimageURL: imageURL},
success: function(data){
console.log("Data sent to server");
confirm("You have successfully logged in with FB");
window.location.reload();
}
});
在我转移到CodeIgniter之前,它完全正常。但是我很困惑没有如何在DB中保存细节或从CodeIgniter中的DB中获取数据。
P.S。我是CodeIgniter的新手。
答案 0 :(得分:0)
您需要在CI中指定绝对路径
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>/index.php/controller/update_function",
// path to the controller
data: {fbname: name,
fbid: id,
fbemail: email,
fbgender: gender,
fbimageURL: imageURL},
success: function(data){
console.log("Data sent to server");
confirm("You have successfully logged in with FB");
window.location.reload();
}
});
问题仅在于您的路径
使用 base_url() - 为此您需要检查网址助手
https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
//您的控制器PHP文件创建Controller.php
class Controller extends CI_Controller
{
public function update_function()
{
// load your model here
$this->load->model("Controller_model");
}
}
//用于Model的PHP文件创建Controller_model.php
class Controller_model extends CI_Model
{
public function update_data()
{
// use database for updating values using post
}
}