未捕获的SyntaxError:意外的令牌:对Desk.com的API调用中的错误

时间:2016-05-05 17:52:09

标签: javascript jquery salesforce

每当我打电话给Desk.com API时,我都会收到错误消息。错误是:

users?callback=jQuery1122045…_1462470520820&_=1462470520821:1 Uncaught SyntaxError: Unexpected token :

我尝试了不同的API端点以及AJAX方法中的不同设置,没有任何变化。这是我的jquery:

$(document).ready(function () {
  //On Click Submission
  $( "#submit" ).click(function(evt) {
    //Prevent Default of changing pages
    evt.preventDefault();
    var data;
    //Variable List
    var email = document.getElementById("InputEmail").value;
    var password = document.getElementById("InputPassword").value;
    var url = document.getElementById("InputUrl").value;
    var input = document.getElementById("csv-file");
    console.log(email,password,url);

    // //Papa Parse Module to parse data
    // Papa.parse(input.files[0], {
    //   header: true,
    //   dynamicTyping: true,
    //   complete: function(results) {
    //     data=results;
    //     console.log(data);
    //   }
    // });

    //Ajax request
    var test_url = "https://zzz-leaflet.desk.com/api/v2/users";
    var test_email = "e*******m";
    var test_pw = "B****1";
    $.ajax(test_url,{
      'contentType':'application/json',
      'accepts':{'json':'application/json'},
      'username':test_email,
      'password':test_pw,
      'method':'GET',
      'dataType':'jsonp',
      success: function(data) {
        console.log(data);
      }
    });
    return;

  })
});

这也是我的HTML:

<!DOCTYPE html>
<html>
<head>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
  <link rel="stylesheet" type="text/css" href="style.css">
  <script src="main.js"></script>
  <script src="node_modules/papaparse/papaparse.min.js"></script>
</head>
<body>
  <div>
    <form>
      <!-- Email Adress -->
      <fieldset class="form-group">
        <label for="exampleInputEmail1">Email address</label>
        <input type="email" class="form-control" id="InputEmail" placeholder="Enter email">
        <small class="text-muted">We'll never share your email with anyone else.</small>
      </fieldset>
      <!-- Password -->
      <fieldset class="form-group">
        <label for="exampleInputPassword1">Password</label>
        <input type="password" class="form-control" id="InputPassword" placeholder="Password">
      </fieldset>
      <!-- URL -->
      <fieldset class="form-group">
        <label for="exampleInputUrl1">URL</label>
        <input type="url" class="form-control" id="InputUrl" placeholder="URL ex. https://companyname.desk.com/">
      </fieldset>
      <!-- FIle Input -->
      <fieldset class="form-group">
        <label for="exampleInputFile">File input</label>
        <input type="file" class="form-control-file" id="csv-file">
        <small class="text-muted">Make sure your CSV is correctly formatted</small>
      </fieldset>
      <div class="radio">
        <label>
          <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
          Cases
        </label>
      </div>
      <div class="radio">
        <label>
          <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
          Customers
        </label>
      </div>
      <div class="radio">
        <label>
          <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" >
          Companies
        </label>
      </div>
      <button type="submit" id="submit" class="btn btn-primary">Submit</button>
    </form>
    <div>
    </body>
    </html>

0 个答案:

没有答案