我有一个CodeIgniter用户面板和一个来自CodeIgniterEnvironment的登录表单,我需要知道如何接受来自它的帖子。
基本上是:
我的应用程序向CodeIgniter应用程序发送带有(登录密码)的POST以成功登录。
观察:我读过关于使用AJAX进行跨域POST的文章,但不起作用。
我试过这个:
$("form").submit(function() {
$.ajax({
url: 'http://localhost/cp/login/auth',
type: 'POST',
crossDomain: true,
data: {login: $('#login').val(), passwd: $('#passwd').val()},
})
});
但当我点击提交按钮时,我重定向到登录页面(CI),但不登录。
我感谢你的耐心。非常感谢。
将此页眉添加到页面中。(http://localhost/cp/login/auth页面)
header('Access-Control-Allow-Origin: *');
对跨域ajax说不。用邮件发送数据。在您的应用程序中检查数据并登录用户,如果有错误则重定向回。
我觉得您正试图通过post将数据从ajax发送到codeigniter函数。那么你应该这样做:
function makeAjaxCall(){
$.ajax({
type: "post",
url: '<?php echo base_url(); ?>" + "MyController/Myfunction',
cache: false,
data: $('#MyForm').serialize()}); }
表格应为
<form name="MyForm" id="MyForm" action="">
将按钮提交为
<input type="button" onclick="makeAjaxCall();" value="Submit"/>
然后在控制器上
class MyController extends CI_Controller{
public function Myfunction(){
$username = $this->input->post('username_field');
$password = $this->input->post('password_field');
//Do my stuff then redirect
}}
希望这会有所帮助。
Hi要从其他登录应用程序获取信息,您需要制作一个Web服务或使用curl
假设您的应用程序进行登录并返回数据是正常的
在另一个应用程序中,你需要像一样使用curl打电话
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "username:password@example.com/controller/method/parm1/param2");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
//print result
var_dump($output);