2017-10-14 1 views
0

내 백엔드 (node.js) 앱에 passport.js를 사용하여 사용자를 등록합니다. 항상 다음과 같은 오류가 발생합니다.위치 오류가있는 Json

ERROR SyntaxError: Unexpected token < in JSON at position 0 at Object.parse() at Response.webpackJsonp.../../../http/@angular/http.es5.js.Body.json (http.es5.js:797) at MapSubscriber.project (signup.component.ts:31)

새로 고침을 한 후 사이트에 가입했습니다. 내 코드에 어떤 문제가 있습니까?

signUp() { 

    this.userNotExist = ""; 
    this.userExist=""; 

     this.http.post('/signup',this.signform.value).map((res: any) => res.json()) 
     .subscribe((res: any) => { 
      console.log('TTTTTTTTT') 
       console.log(res) 
       console.log('TTTTTTTTT') 
       if(res=='EXIST'){ 
        this.userNotExist = ""; 
        this.userExist = 'The email already exists'; 
       }else { 
        this.userExist = ""; 
        this.userNotExist = 'Congrats! You are now signed up'; 
        window.location.reload(); 


       } 
      } 

     ),(error: any) => { 
       console.log(error); 
      } 

} 

내 Node.js를 응용 프로그램 : 당신은 대신 JSON 응답 xml 반응을 얻고있다

passport.use('local-signup', new LocalStrategy({ 
      // by default, local strategy uses username and password, we will override with email 
      usernameField : 'email', 
      passwordField : 'password', 
      nameMainField : 'nameMain', 
      firstNameField: 'firstName', 
      passReqToCallback : true // allows us to pass back the entire request to the callback 
     }, 
     function(req, email, password, done) { 

      // find a user whose email is the same as the forms email 
      // we are checking to see if the user trying to login already exists 
      User.findOne({ 'local.email' : email }).lean().exec(function(err, user) { 
       // if there are any errors, return the error 

       if (err) 
        return done(err); 

       // check to see if theres already a user with that email 
       if (user) { 
        return done(null, false, req.flash('signupMessage', 'Email already exists.')); 
       } else { 

        var newUserS   = new User(); 

        // set the user's local credentials 
        newUserS.local.email = email; 
        newUserS.local.password = newUserS.generateHash(password); // use the generateHash function in our user model 
        newUserS.local.nameMain = req.body.firstName + ' ' + req.body.nameMain; 
        newUserS.local.firstName = req.body.firstName; 
        newUserS.role=0; 
        newUserS.profileImage='/assets/fonts/male.png'; 

        // save the user 
        newUserS.save(function(err, u) { 
         if (err) 
          throw err; 

         return done(null, newUserS); 
        }); 
       } 
      }); 

     })); 

답변

0

여기 내 각 기능입니다. 나는 이것이 다음과 같은 것이라고 확신한다.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE paymentService PUBLIC "-//WorldPay//DTD WorldPay PaymentService v1//EN" 
    "http://dtd.WorldPay.com/paymentService_v1.dtd"> 
<paymentService version="1.4" merchantCode="ExampleCode1"> <!--The merchantCode you supplied originally--> 
    <reply> 
    <orderStatus orderCode="ExampleOrder1"> <!--Not present for parse or security violation errors--> 
     <error code="2"> 
     <![CDATA[Invalid address: Postal code is missing or empty.]]> 
     </error> 
    </orderStatus> 
    </reply> 
</paymentService> 

xml 응답의 첫 번째 문자는 예외이다.

+0

나는 MongoDB Mongoose를 사용하여 데이터를 검색하기 때문에 그렇게 생각하지 않는다. –

+0

네트워크를 확인하십시오. 응답을 JSON에 매핑하는 동안 map ((res : any) => res.json())에서 오류가 발생합니다. 당신은 확실히 XML 응답을 받고 있습니다. – omeralper

+0

좋습니다. 입술 만 작동 –

관련 문제