ionic-framework - SyntaxError:JSON.parse:JSON 数据的第 1 行第 1 列出现意外字符 - IONIC
问题描述
我正在尝试在数据库上注册用户详细信息,但 JSON 变量无法传递。它显示语法错误 this.accsPrvds.postData(body,'process_api.php').subscribe((res:any)=>{ } 函数不起作用正确(如果真假条件不起作用直接运行(.err)语句)
访问提供者.ts
export class AccessProviders{
server:string='http://localhost/api/';
constructor(private http:HttpClient
) { }
postData(body,file){
let headers=new HttpHeaders({
'Content-Type':'application/json; charset=UTF-8'
});
let options= {
headers : headers
}
return this.http.post(this.server + file , JSON.stringify(body),options)
.timeout(590000)
.map(res=>res);
}
}
注册.ts
async tryRegister(){
if(this.your_name==""){
this.presentToast('your name is required');
}else if(this.email_address==""){
this.presentToast('Email is required');
}else if(this.password==""){
this.presentToast('password is required');
}else if(this.confirm_pass!=this.password){
this.presentToast('Password not match');
}else{
this.disabledButton=true;
const loader = await this.load.create({
message:'Please Wait.....',
});
loader.present();
return new Promise(resolve=>{
let body = {
aksi: 'process_register',
your_name: this.your_name,
email_address: this.email_address,
password: this.password,
confirm_pass: this.confirm_pass
}
this.accsPrvds.postData(body,'process_api.php').subscribe((res:any)=>{
console.log("hello");
if(res.success == 'true'){
loader.dismiss();
this.disabledButton=false;
this.presentToast(res.msg);
this.router.navigate(['/login']);
}else {
loader.dismiss();
this.disabledButton=false;
this.presentToast(res.msg);
}
},(err)=>{
loader.dismiss();
this.disabledButton=false;
this.presentAlert('Timeout');
});
});
}
}
process_api.php
<?php
header('Access-Control-Allow-Orgin: *');
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin,Content-Type,Authorization,Accept,X-Requested-With,x-xsrf-token");
header("Content-Type: application/json;charset=utf-8");
include "config.php";
$postjson=json_decode(file_get_contents('php://input'),true);
if($postjson['aksi']=="process_register"){
$checkmail=mysqli_fetch_array(mysqli_query($mysqli,"SELECT email_address FROM register WHERE email_address='$postjson[email_address]'"));
if($checkmail['email_address']==$postjson['email_address']){
$result=json_encode(array('success'=>false,'msg'=>'Email Already Registered'));
}else{
$password=md5($postjson['password']);
$insert = mysqli_query($mysqli,"INSERT INTO register SET
your_name ='$postjson[your_name]',
email_address ='$postjson[email_address]',
password ='$password',
confirm_pass ='$postjson[confirm_pass]'
");
if($insert){
$result=json_encode(array('success'=>true,'msg'=>'Register Successfully'));
}else{
$result=json_encode(array('success'=>false,'msg'=>'Register error'));
}
}
echo $result;
}
?>
用户注册成功,但在 this.accsPrvds.postData(body,'process_api.php').subscribe((res:any)=>{ } 和 json 错误上显示超时消息...
任何人请帮助
解决方案
请删除分配给 res 的对象类型“任何”
推荐阅读
- python - Python TypeError:使用 witn open() 时的字符串格式
- amazon-web-services - 外部合作伙伴在 AWS 账户中上传 S3 对象的机制
- node.js - 检查某些表情符号是否有反应 - Discord.js
- python - 改变变量的值,同时保持它们的总和不变
- linkedin - 可以在网站上显示 LinkedIn 公司动态吗?
- r - 如何从系数列表中获取 lm 对象并在 R 中截取
- angular - 每个功能的授权(AWS+Angular+Serverless)
- sql - 论坛热门话题sql按日期排序然后回复
- r - 对于满足 R 中特定条件的情况,如何用 0 替换缺失值?
- sql - oracle-sql 上的权限不足错误