Q:

$.ajax is not working but $.getJSON is working

I am trying to get share count of pininterest and below code is working well 
var pi_like_count = 0;
PIUrl = "https://api.pinterest.com/v1/urls/count.json?url=" + url1 + "&format=jsonp" + '&callback=?'
$.getJSON(PIUrl, function (data) {
    pi_like_count = data.count;

    alert(pi_like_count +' pininterest');
});

but when I am trying to put below code issue is coming as
var pi_like_count = 0;
PIUrl = "https://api.pinterest.com/v1/urls/count.json?url=" + url1 + "&format=jsonp" + '&callback=?'
$.ajax({
    method: 'GET',
    url: PIUrl,
    success: function (data) {
        pi_like_count = data.count;

        alert(pi_like_count + ' pininterest');
    },
    error: function (data) {
        alert('error' + data.count + ' pininterest');
        console.log(data);
    },
    async: false
}); 

Console.log error as 
promise: function promise()
readyState: 4
responseText: "{\"error\":\"Invalid callback, use only letters, numbers, square brackets, underscores, and periods.\"}"

This issue is coming when I am using $.ajax, I had tried same to get facebook share count and is working well but pininterest is not working
more explaination
 function GetScores(url) {
    var FBUrl, TWUrl, LNUrl, GLUrl, PIUrl;
    var url1 = "";
    url1 = encodeURIComponent(url1 || url);  

    //Fetch counters from PInterest
    var pi_like_count = 0;
    PIUrl = "https://api.pinterest.com/v1/urls/count.json?url=" + url1 + "&format=jsonp" + '&callback=?'  
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: PIUrl,
        success: function (data) {
            pi_like_count = data.count;
            alert(pi_like_count + ' pininterest');
        }        ,
        complete: function (jqXHR, data) {
            pi_like_count = data.count;
            alert(pi_like_count + ' pininterest complete');
        },
        error: function (req, status, error) {
            alert('error');
        },
        async: false
    });

    //Fetch counters from Facebook
    var fb_share_count = 0;

    FBUrl = "https://graph.facebook.com/?id=" + url1 + "&format=json";

    $.ajax({
        type: 'GET',
        url: FBUrl,
        success: function (data) {
            fb_share_count = data.share.share_count;
            alert(fb_share_count+' facebook');
        },
        async: false
    });
    var totalshare = parseInt(fb_share_count) + parseInt(pi_like_count);

    return totalshare;
    }

Here Facebook count and total share count is get then after the pinterest count alert is showing i.e. when this function is calling second time then after pinterest is giving old count.

A:

Try it:
function GetScores(url, onCountTotal) {
    var FBUrl, TWUrl, LNUrl, GLUrl, PIUrl;
    var url1 = "";
    url1 = encodeURIComponent(url1 || url);
    //Fetch counters from PInterest
    var pi_like_count = 0;
    PIUrl = "https://api.pinterest.com/v1/urls/count.json?url=" + url1 + "&format=jsonp" + '&callback=?';
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: PIUrl,
        success: function (data) {
            pi_like_count = data.count;
            var fb_share_count = 0;
            FBUrl = "https://graph.facebook.com/?id=" + url1 + "&format=json";
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: FBUrl,
                success: function (data) {
                    fb_share_count = data.share.share_count;
                    var totalshare = parseInt(fb_share_count) + parseInt(pi_like_count);
                    onCountTotal(totalshare);
                    //alert(fb_share_count + ' facebook');
                },
                error: function (data) {
                    onCountTotal(-1);
                },
                async: true
            });
        },
        error: function (req, status, error) {
            onCountTotal(-1);
        },
        async: true
    });
}

//EXAMPLE HERE CALL FUNCTION WITH CALLBACK
GetScores("http://www.google.com", function (count) {
    alert("Count = " + count);
});

