if(activePage.attr('id') === 'register_page') {
$(document).on('click', '#submit', function() { // catch the form's submit event
if($('#fname').val().length > 3 && $('#lname').val().length > 3 && $('#username').val().length > 4 && $('#email').val().length > 5 ){
userHandler.username = $('#username').val();
// Send data to server through the Ajax call
//$.post( "http://127.0.0.1/projects/register2.php", $( "#register-user" ).serialize() );
// action is functionality we want to call and outputJSON is our data
$.ajax({
url: 'http://127.0.0.1/projects/services/register.php',
data: {action : 'registration', formData : $('#register-user').serialize()},
type: 'post',
async: true,
contentType: "application/json; charset=utf-8",
dataType: 'JSON ',
beforeSend: function() {
// This callback function will trigger before data is sent
$.mobile.loading('show'); // show Ajax spinner
},
complete: function() {
// trigger on data sent/received complete
$.mobile.loading('hide'); // hide Ajax spinner
},
success: function (result) {
// Check if registration successful
if(result.status == 'success') {
userHandler.status = result.status;
$.mobile.changePage("#categories");
} else if(result.status == 'failure'){
$("#register-error").text("System failure... please try again!").show().fadeOut(3000);
}
else if(result.status == 'taken'){
alert('Username or email is taken!');
}
},
error: function (xhr, status, error ) {
// This callback function will trigger on unsuccessful action
//alert('Network error has occurred please try again!'); >> kanyagia hapa
$("#register-error").text(xhr.status+ "Network error... please check and try agin!").show().fadeOut(3000);
}
});
ajax调用返回网络错误>> 404
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- doupao1978 2015-08-03 07:04关注
The php file>> as shown below with Access headers works fine, without the access, the xdk emulator returns network error
<?php header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PUT'); require './services/config.php'; if(!empty($_POST)) { $errors=0; if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['username']) || empty($_POST['email']) || empty($_POST['pword'])) { $errors++; $error_msg="Please fill all the fields"; $status =(true); echo '{"empty":'.json_encode($status).'}'; } //pick all the data $fname=$_POST['fname']; $lname=$_POST['lname']; $usern=$_POST['username']; $email=$_POST['email']; $pass=$_POST['pword']; $role=$_POST['role']; //encrypt pw $encrypt_pw= md5($pass); //check if errors are still 0 and check user existence if($errors==0) { $query="SELECT * FROM users WHERE username=:aa OR email=:bb"; $query_params=array( ':aa'=>$usern, ':bb'=>$email ); try{ $stmt=$db->prepare($query); $result=$stmt->execute($query_params); } catch (Exception $ex) { $errors++; $error_msg="Server failure... please try again"; $status =("0"); echo '{"status":'.json_encode($status).'}'; } $row=$stmt->fetch(); if($row) { $errors++; $error_msg="Username or email already exists"; $status =(true); echo '{"exists":'.json_encode($status).'}'; } //if errors still 0 if($errors==0) { $query="INSERT INTO users(fname, lname, username, email, password, role, created_at) VALUES(:aa, :bb, :cc, :dd, :ee,:ff, NOW())"; $query_params=array( ':aa'=>$fname, ':bb'=>$lname, ':cc'=>$usern, ':dd'=>$email, ':ee'=>$encrypt_pw, ':ff'=>$role ); try{ $stmt=$db->prepare($query); $result=$stmt->execute($query_params); } catch (Exception $ex) { $errors++; $error_msg="Server failure... please try again"; $status = array("status" => "failure"); echo json_encode($status); } if($errors==0) { //registration successful $success_msg="You registered"; $status =(true); echo '{"success":'.json_encode($status).'}'; } } } } /* some interface here.. */ ?>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Python报错怎么解决
- ¥15 simulink如何调用DLL文件
- ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
- ¥30 线性代数的问题,我真的忘了线代的知识了
- ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
- ¥188 需要修改一个工具,懂得汇编的人来。
- ¥15 livecharts wpf piechart 属性
- ¥20 数学建模,尽量用matlab回答,论文格式
- ¥15 昨天挂载了一下u盘,然后拔了
- ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题