How to Call the REST API in jQuery and Obtain a Response

Asked 2 months ago, Updated 2 months ago, 5 views

I am currently writing a code to call the REST API from jQuery to retrieve the results.

[What I want to do]
 Use jQuery to access Paypal's following sandbox URL:
 https://api-3t.sandbox.paypal.com/nvp

As for the result, the following string will be returned, so I would like to obtain it in jQuery.
 ACK = Failure & L_ERRORCODE 0 = 81002 & L_SHORTMESSAGE 0 = Unspecified %20 Method & L_LONGMESSAGE 0 = Method %20 Specified %20is %20 Not %20 Supported & L_SEVERITYCODE 0 = Error

[Question]
 http://semooh.jp/jquery/api/ajax/jQuery.ajax/options/

I wrote the following code with reference to the above documentation, but I couldn't get the response string, so I ended up in the function of the error.

<!doctype html>
<html lang="ja">
<head>
    <metacharset="UTF-8">
    <title>jQuery REST API sample</title>
    <script type="text/javascript"src="./js/jquery-1.11.3.min.js"></script>
</head>
<body>
<h2>After retrieving PayPal data from the Rest API, use jQuary to view it</h2>

<h2>Read with $ajax</h2>
<ul class="ajax"></ul>
<script>
    $.ajax({
        type: 'GET',
        url: 'https://api-3t.sandbox.paypal.com/nvp',
        dataType: 'text'
    }).done(function(text){
            varlen=text.length;
            alert("success:"+len);
            for(vari=0;i<len;i++){
                $(".ajax").append('<li><a href="'+text[i].link+'">'+text[i].title+'<a></li>');
            }
    }).fail(function(text){
            varlen=text.length;
            alert("error:"+len);
            $('.ajax') .append(" Failed to load.");
    });
</script>
</body>
</html>

Could someone please tell me what caused it?
Thank you for your cooperation.

jquery paypal ajax rest

2022-09-30 11:45

2 Answers

In principle, js cannot read files on other servers. (Cross Domain Problem)
It is possible to obtain information by php and so on and receive it by js.

JS: Cross-domain Ajax communication|ARTICLE|goma


2022-09-30 11:45

I'm sorry, but I think it's a fundamental problem with this question, but the endpoint of PayPal's REST API is

https://api.sandbox.paypal.com

in

https://api-3t.sandbox.paypal.com/nvp

is called the NVP (classic) API.

https://developer.paypal.com/docs/api/ #api-operations

The REST API requests and responses remain the same as JSON.

That's all.


2022-09-30 11:45

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.