0
function getInfo()
{

    var URL="https://api-oauth2.mendeley.com/oauth/authorize?client_id=374&redirect_uri=https://localhost/api/mendeley/mendeley.php&response_type=code&scope=all&JSON=1";
    $.ajax({
        url: URL,
        type: 'get',
        dataType: "jsonp",
        jsonpCallback: "https://192.168.2.210/api/mendeley/mendeley.php",
        converters: {
            'text json': true
        },
        success: function (data) {
            console.log(data.content);


        },
        error: function(e) {
            console.log(e);
        }
    });
}

when I call this function this gives me error
SyntaxError: syntax error

2
  • on what line do you get the error? and is it syntax error or cross origin error ?
    – nl-x
    May 22, 2014 at 12:43
  • if I put alert in error:function(e){} it gives me that alert
    – Sayali
    May 23, 2014 at 6:57

1 Answer 1

0

You have several problems.


From the jQuery documentation:

jsonpCallback
Type: String or Function()
Specify the callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. As of jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback is set to the return value of that function.

https://192.168.2.210/api/mendeley/mendeley.php is not a valid JavaScript function name.


If I visit https://api-oauth2.mendeley.com/oauth/authorize?client_id=374&redirect_uri=https://localhost/api/mendeley/mendeley.php&response_type=code&scope=all&JSON=1 or https://api-oauth2.mendeley.com/oauth/authorize?client_id=374&redirect_uri=https://localhost/api/mendeley/mendeley.php&response_type=code&scope=all&JSON=1&callback=something, I get an HTML document prompting me to log in.

You need to hit a real JSONP endpoint to use JSONP.

2
  • thank you for your ans. I put some lines in my ajax code jsonpCallback: "result", jsonp: 'callback', and function result(data) { alert(data); console.log(data); };
    – Sayali
    May 23, 2014 at 6:17
  • @sayali — This answer points out two problems. You addressed one of them. It isn't surprising that it doesn't work.
    – Quentin
    May 23, 2014 at 6:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.