级别:新手(JavaScript、jQuery、CodeIgniter)
我创建了一个更改密码的功能,然后我使用 chrome 浏览器在 localhost 中运行它。当我想从我的 JavaScript 调用 PHP 函数时,我遇到了麻烦。Chrome 控制台说该页面未找到,该文档的链接是 jquery.min.js:2
我不知道我应该做什么,因为我是 jQuery 新手。这是我在 pengaturan.html 中的 html
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="css/style1.css" />
<script src="jq/jquery.mobile-1.2.0.min.js"></script>
<script src="jq/jquery-1.9.1.min.js"></script>
<script src="jq/jquery-1.8.2.min.js"></script>
<script src="date/js/jquery.min.js"></script>
<script src="date/js/kendo.web.min.js"></script>
<script src="date/js/console.js"></script>
<script src="jq/proses/set_ip.js"></script>
<script src="jq/proses/newpass/newpass.js"></script>
<script src="jq/proses/script.js"></script>
<title>edc - e diabet consult</title>
</head>
<body>
<h1 align="center">Pengaturan</h1>
<p align="left" class="navigation">
<a href="settings.html" class="back">
<img src="ico/kembali.png">
</a>
</p>
<form id="form_pengaturan" action="post">
<p align="center">
<strong>Password lama:</strong><br />
<input type="password" name="pass" id="pass"/><br />
<strong>Password baru:</strong><br />
<input type="password" name="newpass" id="newpass"/><br />
<strong>Konfirmasi password baru:</strong><br />
<input type="password" name="confnewpass" id="confnewpass"/><br /><br/>
<input type="button" value="Simpan" onclick="cek()" id="simpan" class="button"/>
<input type="reset" value="Reset" class="button"/>
</p>
</form>
</body>
</html>
这是我在 newpass.js 中的 javascript
/*Don't forget to add set_ip.js and jquery before you use this script in HTML page to make it work*/
var urlini = seturl();
var part= 'newpass/';
$(document).ready(function() {
currentYear = (new Date).getFullYear();
$("#tgllahir_inp").kendoDatePicker({
// defines the start view
start: "year",
min: new Date(currentYear-50,'0','01'),
max: new Date(currentYear-14,'0','01'),
// defines when the calendar should return date
depth: "day",
// display month and year in the input
format: "yyyy-MM-dd"
});
});
function cek() {
pass = /^([-a-z0-9_-])+$/i.test($("#pass").val());
newpass = /^([-a-z0-9_-])+$/i.test($("#newpass").val());
confnewpass = /^([-a-z0-9_-])+$/i.test($("#confnewpass").val());
var form_reg = $("input").val();
if(form_reg == "")
{
alert("Semua data harus diisi.");
}
else if($("#newpass, #confnewpass").val().length == 0 || $("#newpass, #confnewpass").val().length < 5 || $("#newpass, #confnewpass").val().length > 15)
{
alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda lebih dari 5 dan kurang dari 15 karakter.");
}
else if( !pass || !newpass || !confnewpass || $("#newpass").val() != $("#confnewpass").val())
{
alert("Terdapat kesalahan atau data kosong pada pengisian data.\nPastikan password Anda sesuai.");
}
else
{
$.post(urlini+part+'cek',
$('#form_pengaturan').serialize(),function(msg){
if(msg == '1')
{
alert("Data berhasil disimpan!");
window.location="index.html";
}
else if(msg == '0')
{
alert("Password yang anda masukkan tidak benar!");
}
});
}
}
这是我在 newpass.php 中的 php 控制器(服务器端)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class newpass extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('newpass_model','npmod');
}
function cek()
{
$q = $this->npmod->pasien_pass();
echo $q;
}
}
?>
这是我在 newpass_model.php 中的 php 模型(服务器端)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class newpass_model extends CI_Model {
public function pasien_pass(){
$id = $this->session->userdata('id');
$pass = md5($this->input->post("pass"));
$query = $this->db->where("iduser",$id)->get("user");
if( $query->num_rows() == 1 ) {
$row = $query->row();
$oldpass= $row->password;
if($pass==$oldpass)
{
$newpass = md5($this->input->post("newpass"));
$confnewpass = base64_encode($this->input->post("confnewpass"));
$data = array(
'password' => $newpass,
'passbit_user' => $confnewpass
);
$this->db->where('iduser',$id);
$this->db->update('user',$data);
return"1";
}
else
{
return "0";
}
} else {
return "0";
}
}
}
?>
当我运行它时,Chrome 控制台说该页面未找到并且该文档的链接是 jquery.min.js:2 你知道我应该怎么做吗?