2

i have to pass header information while posting a url and want to pass raw data in the url can any on help me on this

i have tried

function test(){
    alert("test");
        $.ajax({
            type:"POST",
            beforeSend: function (request)
            {
                request.setRequestHeader("X-APIKEY", "y5q9q1at8u-1uf4bao2yq-bsjdj3gh1g-u9ymh1t2f8-tt85pn4r50");
            },
            url: "https://backoffice.hostcontrol.com/api/v1/domain-is",
            data: {"domain": "mahrosh.com"},
            processData: false,
            success: function(msg) {
                alert(msg);
                $("#results").append("The result =" + StringifyPretty(msg));
            }
    });
}

its not returning me results

Ben Fortune
  • 31,623
  • 10
  • 79
  • 80
Salman
  • 21
  • 2

1 Answers1

0

You can add header variables as per given in below described code

function test(){
alert("test");
$.ajax({
    type:"POST",
    headers: { 'X-APIKEY': 'y5q9q1at8u-1uf4bao2yq-bsjdj3gh1g-u9ymh1t2f8-tt85pn4r50'},
    url: "https://backoffice.hostcontrol.com/api/v1/domain-is",
    data: {"domain": "mahrosh.com"},
    processData: false,
    success: function(data) {
        alert(JSON.stringify(data));
    },
    error: function(data){
        alert(JSON.stringify(data));
    }
});
}

If server gives error in response than you have idea about it so i added the error section as well ...

Neo
  • 407
  • 5
  • 18
  • it is returning nothing no reply no text – Salman Dec 18 '14 at 05:03
  • @Salman the response I got is {"readyState":0,"responseText":"","status":0,"statusText":"error"} – Neo Dec 18 '14 at 06:21
  • @Salman Please take anote that I got this message also in the console .. XMLHttpRequest cannot load https://backoffice.hostcontrol.com/api/v1/domain-is. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. – Neo Dec 18 '14 at 06:33
  • @Salman so it might be the issue of localhost .. are you doing the same means accessing the api through localhost .. ? – Neo Dec 18 '14 at 06:34