• Hi Team,

    I am developing a API using Jquery Ajax Call method to call post of my sites.
    I am using “oauth wordpress plugin” to authenticate the Get Call using “Client Credentials ” method however it does not return anything.
    My code is :

    $('document').ready(function() {
         var request = $.ajax({
           url: "http://measinki.com/wp-json/wp/v2/posts",
           type: "GET",
    	   connection: "keep-alive",
           crossDomain: true,
           username:"my-Client ID",
           password:"My-secret-key",
           contentType: "application/json",
           mimeType: "application/json",
             headers:{ 'Access-Control-Allow-Origin': '*',
                      "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
                     }
    	  });
    	request.done(function(msg) {
             console.log(msg); 
    
    });

    I do receive error in Console ” Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.”

    Any help will appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello sharadmani02,

    Can you please try by adding the below line of code in Response headers:

    “Access-Control-Allow-Methods”: “POST, GET”,

    Thanks

    Thread Starter sharadmani02

    (@sharadmani02)

    Hi,
    I did try the same. Now getting error “Uncaught SyntaxError: Unexpected token ILLEGAL”

    New code is :

    $('document').ready(function() {
         var request = $.ajax({
           url: "http://measinki.com/wp-json/wp/v2/posts",
           type: "GET",
    	   connection: "keep-alive",
           crossDomain: true,
    	   username:"GKXw1WSmtDtGTtrpy0CmRstOrlnxXI",
           password:"Br@mEsjbug3QJGkqANRZmSCJJ5dywyV3w$02",
           contentType: "application/json",
           mimeType: "application/json",
             headers:{
                 "Access-Control-Allow-Origin" : "*",
                "Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
                "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
             		}
    	  });
    	request.done(function(msg) {
             console.log(msg); 
    
    });
    	});

    Thread Starter sharadmani02

    (@sharadmani02)

    Sorry I did miss ” in the end of "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With

    Now again initial error message is there ” Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.”

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Client Credentials Jquery get method’ is closed to new replies.