Paba
Paba

Reputation: 1115

How to send XML request in JavaScript

I have an eye tracker (mirametrix) running as a server in localhost. In order to capture data from this I should send a xml request as given below;

SEND:<GET ID="TIME_TICK_FREQUENCY" />

I have a web-app running as the client and I need to make a request to this server through that. I wrote the following code but it doesn't seem to send the request properly to the server.

var request = $.ajax({
            url: "http://127.0.0.1:4242",
            type: "GET",
            dataType: "xml",
            data: { 
                data:'<GET ID="TIME_TICK_FREQUENCY" />'

            },

        });

Can someone please help me with this ?

Thanks in advance

Upvotes: 1

Views: 2764

Answers (2)

Evert
Evert

Reputation: 99816

this is not plain javascript.. looks more like jquery.. also what do you mean with 'properly'. It's kind sending it, but not really? Aside from that, I see the following problems

  • The url is wrong, and although your browser may handle it, your url should end with a slash.
  • Your xml is invalid. Needs to start with <?xml version="1.0"?>.
  • If you accessed this script through a different host than 127.0.0.1., or if the script is running on a different port than 4242, this will not work without CORS headers on the server.

Upvotes: 1

dinesh707
dinesh707

Reputation: 12592

$.ajax({
    url: ajaxurl,
    data: "<root><blah><blah></root>", 
    type: 'POST',
    contentType: "text/xml",
    dataType: "text",
    success : parse,
    error : function (xhr, ajaxOptions, thrownError){  
        console.log(xhr.status);          
        console.log(thrownError);
    } 
}); 

I think you need to post it.

Upvotes: 1

Related Questions