0
var url = "http://www.api.sitehoover.com/api/";
var request = {};
request.id = "1";
request.method = "add_page";
request.params = "a7eede94cdc5e5aa77bd8db969ab0089";
request.params.folder_oid = "9";
request.params.url = "http://www.google.com/";
request.params.title = "My Google Page";
request.jsonrpc = "2.0";

function displaySearchResult(response) {
alert("In displaySearchResult.... ");
    if (response.result)
            alert(response.result);

    else if (response.error)
            alert("Search error: " + response.error.message);
};

$.post(url, JSON.stringify(request), displaySearchResult, "json");`

Am trying JSON RPC call. When I checked Chrome console, I found: enter image description here

Even in Mozilla console, it says 401 authorization error. When I started digging about this error, I hit into 'Single domain Policy' and other stuff which quoted that adding header for accepting the calls from origin domain or using JSONP resolved the issue.

I tried them too but to no vail. Can someone help with the JSONP?

Community
  • 1
  • 1
Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
  • If the server does not support JSONP or CORS, you simply cannot use browser JavaScript to directly access it. – Felix Kling Oct 23 '15 at 00:32
  • Server (http://www.sitehoover.com/en/api/) accepts it. Even then its throwing this error. AM not sure how to go forward. – Anuj Balan Oct 23 '15 at 01:28
  • Ah well, you cannot make POST requests without CORS. JSONP only works with GET requests. – Felix Kling Oct 23 '15 at 01:49
  • So if I want to use the API that they are exposing, how do I do it? – Anuj Balan Oct 23 '15 at 02:30
  • Putting aside CORS for a minute, you're constructing the `params` field in the json-rpc packet incorrectly. `params` should be an `Array` (not a `String`) according to the example. Something like: `request.params = ["a7eede94cdc5e5aa77bd8db969ab0089", { "folder_oid": "9", "url": "http://www.google.com/", "title": "My Google Page"}]; ` – David-SkyMesh Dec 05 '15 at 02:27

0 Answers0