pamz peppo

pamz peppo

  • NA
  • 4
  • 659

IONIC -SyntaxError: JSON.parse: unexpected character at line

Jan 27 2020 6:12 PM
Access-provider.ts
  1. import {Injectable} from '@angular/core';  
  2. import{HttpClient,HttpHeaders,HttpErrorResponse} from '@angular/common/http';  
  3. import 'rxjs/add/operator/map';  
  4. import 'rxjs/add/operator/timeout';  
  5. @Injectable()  
  6. export class AccessProviders{  
  7. server:string='http://localhost/api/';  
  8. constructor(private http:HttpClient  
  9. ) { }  
  10. postData(body,file){  
  11. let headers=new HttpHeaders({  
  12. 'Content-Type':'application/json; charset=UTF-8'  
  13. });  
  14. let options= {  
  15. headers : headers  
  16. }  
  17. return this.http.post(this.server + file , JSON.stringify(body),options)  
  18. .timeout(590000)  
  19. .map(res=>res);  
  20. }  
register.ts
  1. async tryRegister(){  
  2. if(this.your_name==""){  
  3. this.presentToast('your name is required');  
  4. }else if(this.email_address==""){  
  5. this.presentToast('Email is required');  
  6. }else if(this.password==""){  
  7. this.presentToast('password is required');  
  8. }else if(this.confirm_pass!=this.password){  
  9. this.presentToast('Password not match');  
  10. }else{  
  11. this.disabledButton=true;  
  12. const loader = await this.load.create({  
  13. message:'Please Wait.....',  
  14. });  
  15. loader.present();  
  16. return new Promise(resolve=>{  
  17. let body = {  
  18. aksi: 'process_register',  
  19. your_name: this.your_name,  
  20. email_address: this.email_address,  
  21. password: this.password,  
  22. confirm_pass: this.confirm_pass  
  23. }  
  24. this.accsPrvds.postData(body,'process_api.php').subscribe((res:any)=>{  
  25. console.log("hello");  
  26. if(res.success == true){  
  27. loader.dismiss();  
  28. this.disabledButton=false;  
  29. this.presentToast(res.msg);  
  30. this.router.navigate(['/login']);  
  31. }else {  
  32. loader.dismiss();  
  33. this.disabledButton=false;  
  34. this.presentToast(res.msg);  
  35. }  
  36. },(err)=>{  
  37. loader.dismiss();  
  38. this.disabledButton=false;  
  39. this.presentAlert('Timeout');  
  40. });  
  41. });  
  42. }  
  43. }  
process_api.php
  1. header('Access-Control-Allow-Orgin: *');  
  2. header("Access-Control-Allow-Credentials: true");  
  3. header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS");  
  4. header("Access-Control-Allow-Headers: Origin,Content-Type,Authorization,Accept,X-Requested-With,x-xsrf-token");  
  5. header("Content-Type: application/json;charset=utf-8");  
  6. include "config.php";  
  7. $postjson=json_decode(file_get_contents('php://input'),true);  
  8. if($postjson['aksi']=="process_register"){  
  9. $checkmail=mysqli_fetch_array(mysqli_query($mysqli,"SELECT email_address FROM register WHERE email_address='$postjson[email_address]'"));  
  10. if($checkmail['email_address']==$postjson['email_address']){  
  11. $result=json_encode(array('success'=>false,'msg'=>'Email Already Registered'));  
  12. }else{  
  13. $password=md5($postjson['password']);  
  14. $insert = mysqli_query($mysqli,"INSERT INTO register SET  
  15. your_name ='$postjson[your_name]',  
  16. email_address ='$postjson[email_address]',  
  17. password ='$password',  
  18. confirm_pass ='$postjson[confirm_pass]'  
  19. ");  
  20. if($insert){  
  21. $result=json_encode(array('success'=>true,'msg'=>'Register Successfully'));  
  22. }else{  
  23. $result=json_encode(array('success'=>false,'msg'=>'Register error'));  
  24. }  
  25. }  
  26. echo $result;  
  27. }  
The register.ts page subscribe(res:any)=>{This part} cannot run,directly run on ,(err){ }part ,If value registered database successfuly execute also (err){} function
 
How Can i Solve ??

Attachment: register.zip