0
votes

This is my ajax code:

    var param = "<ClientOrder xmlns='http://www.eysnap.com/mPlayer'>";
    param += "<ClientId>CRF-1</ClientId>";
    param += "<UserKey>598zxc8ddl45a3cvScuk</UserKey>" ;
    param += "<PassKey>p1re254l3jd83os00cpk</PassKey>";
    param += "<OrderId>123132323435</OrderId>";
    param += "</ClientOrder>";

    $.ajax({

        url: URL, 
        data: param, 
        type: 'POST',
        contentType: "text/xml",
        dataType: "text",
        success: function(result){
            alert('success');
            $("#div1").html(result);
        },
        error: function (xhr) {
            alert('error');
            $("#div1").html(xhr.responseText);
        }
    });

The service I'm calling is restful. The crazy thing is that when I call a GET service, it returns the data correctly, but with POST service it gives this error:

XMLHttpRequest cannot load [url]. Response for preflight has invalid HTTP status code 405

Any help will be appreciated.

1
The servica provider decides the method, not the caller. If it is provided as get, then you have to comply. It may not be REST compliant, but that's the way it is :-)thst
HTTP Error 405 Method not allowed which means they do not allow POST requests.Yvo Cilon
no actually, thats another service that allows GET. This service is specifically made for POST. I need to send a POST request.Tahreem Iqbal
@YvoCilon: it can't be possible. I'm already calling this service with POST in a C# code. Now when I try to do this with JQuery, it doesn't work!Tahreem Iqbal
CORS issues ... if the site doesn't allow CORS then the site doesn't allow CORS ... server -> server will work, browser -> server will require CORS enabled on the serverJaromanda X

1 Answers

0
votes

Turns out, it was namespace issue.

<ClientOrder xmlns='http://www.eysnap.com/mPlayer'>

I changed the namespace to correct one.