4

It gaves me error when I m trying to call this controller .

hiren.controller('hirenz' , function($scope , $http , $location , $routeParams){
    $http.post((rootURL + "music") , {'alpha' : $routeParams.alpha , 'name' : $routeParams.name ,
        'album' : $routeParams.albumname }).success(function(data){
        var parsedJson = JSON.parse(data) ;
        console.log(parsedJson.name);
    });
});

Here is the "data" that i am calling from server

{
    "name": [
        "Adhar - Adhar ",
        "Adhar - Adhare Opshori ",
        "Adhar - Aj Neshay "
    ],
    "url": [
        "http://music-com-bd.com/Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music.com.bd).mp3",
        "http://music-com-bd.com/Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music.com.bd).mp3",
        "http://music-com-bd.com/Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music.com.bd).mp3"
    ]
}
1
  • 'SyntaxError: Unexpected token o' Commented Jan 23, 2014 at 12:17

2 Answers 2

10

You are parsing something which is not a string. It might be already in form of JSON object. You do not need to parse it. If you change var parsedJson = JSON.parse(data) ; to var parsedJson = data; The error will go off.

Sign up to request clarification or add additional context in comments.

Comments

3

This error occurs when JSON is not properly formed. Check it with JSLint

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.