Uncaught SyntaxError: Unexpected token : when using api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ruslan
    Senior Member
    • Aug 2014
    • 102

    Uncaught SyntaxError: Unexpected token : when using api

    when i try to get data from api i get this error in the console

    Code:
    user?callback=jQuery21406149524166248739_1436556997509&_=1436556997510:1 Uncaught SyntaxError: Unexpected token :

    Code:
        var creds = {
        username: "username",
        password: "password"
    };
    var credentials = btoa(creds.username + ":" + creds.password);
    $.ajaxSetup({
        xhrFields: { withCredentials: false },
        beforeSend: function (xhr, settings) {
            xhr.setRequestHeader("Authorization", "Basic" + credentials);
            return true;
        }
    });
    
    $.ajax({
        url: 'http://site.com/api/v1/App/user',
        type: 'GET',
        dataType: 'jsonp',
        async: false,
        success: function (data) {
            console.log(data);
        }
    });
  • Ruslan
    Senior Member
    • Aug 2014
    • 102

    #2
    i also tried: and the same error:
    Uncaught SyntaxError: Unexpected token :
    Code:
    var username = 'admin';
    var password = '1';
    
    $.ajax
    ({
      type: "GET",
      dataType: 'json',
      async: false,
      url: "http://demo.espocrm.com/basic/api/v1/App/user?callback=?",
      headers: {
        "Authorization": "Basic " + btoa(username + ":" + password)
      }
    })
    .done(function(){
        alert('Authenticated!')
    })
    .fail(function(){
        alert('Error!')
    });

    Comment

    • yuri
      Member
      • Mar 2014
      • 8627

      #3
      No clue what it is, Code seems to be correct.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • Ruslan
        Senior Member
        • Aug 2014
        • 102

        #4
        HI,
        if there is problem with the code maybe you can add working example to doc so we can have a start point.

        and whats wrong with this code?

        Comment

        • Ruslan
          Senior Member
          • Aug 2014
          • 102

          #5
          some help?

          Comment

          • yuri
            Member
            • Mar 2014
            • 8627

            #6
            Really have no time.
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment

            Working...