简体   繁体   English

如何在 JavaScript 中发送 XML 请求

[英]How to send XML request in JavaScript

I have an eye tracker (mirametrix) running as a server in localhost.我有一个眼动仪(mirametrix)作为本地主机中的服务器运行。 In order to capture data from this I should send a xml request as given below;为了从中捕获数据,我应该发送一个 xml 请求,如下所示;

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提前致谢

$.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.我认为你需要发布它。

this is not plain javascript.. looks more like jquery.. also what do you mean with 'properly'.这不是普通的 javascript.. 看起来更像 jquery.. 还有你所说的“正确”是什么意思。 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. url 是错误的,尽管您的浏览器可能会处理它,但您的 url应该以斜杠结尾。
  • Your xml is invalid.您的 xml 无效。 Needs to start with <?xml version="1.0"?> .需要以<?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.如果您通过与 127.0.0.1. 不同的主机访问此脚本,或者如果脚本在与 4242 不同的端口上运行,则如果服务器上没有CORS标头,这将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM