简体   繁体   English

使用Musixmatch API的jquery ajax ParseError

[英]jquery ajax ParseError with Musixmatch API

I am using jQuery 1.11.3 with the following code: 我使用jQuery 1.11.3与以下代码:

$.ajax({
    type: "GET",
    data: {
        apikey: apiMusixkey,
        q_track: q,
        page_size: 10
    },
    url: "http://api.musixmatch.com/ws/1.1/track.search",
    dataType: "jsonp",
    contentType: 'application/json',
    success: function(data) {
        //console.log(json); 
    },
    error: function(jqXHR, textStatus, errorThrown) {
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    }
});

I am getting the error: 我收到错误:

parseError... [] was not called 没有调用parseError ... []

What am I doing wrong? 我究竟做错了什么?

Looks like you are missing a few things on your ajax. 看起来你在ajax上遗漏了一些东西。 You need to specify the name of the callback function to handle the jsonp. 您需要指定回调函数的名称来处理jsonp。 Also, there's a format parameter you need to use with the musixmatch api. 此外,还需要与musixmatch api一起使用的格式参数。 Checkout this plunker: http://plnkr.co/edit/XW6TFUJquW8o8EVpEEgU?p=preview 检查这个plunker: http ://plnkr.co/edit/XW6TFUJquW8o8EVpEEgU?p = preview

$(function(){

  $.ajax({
    type: "GET",
    data: {
        apikey:"309788821d050a0623303261b9ddedc4",
        q_track:"back to december",
        q_artist:"taylor%20swift",
        f_has_lyrics: 1,
        format:"jsonp",
        callback:"jsonp_callback"
    },
    url: "http://api.musixmatch.com/ws/1.1/track.search",
    dataType: "jsonp",
    jsonpCallback: 'jsonp_callback',
    contentType: 'application/json',
    success: function(data) {
        console.log(data); 
    },
    error: function(jqXHR, textStatus, errorThrown) {
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    }    
  });
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM