AJAX XML issue

Completado Publicado hace 8 meses Pagado a la entrega
Completado Pagado a la entrega

I am writing a small application to display log files using ajax and python.

I am returning null with the following error in the Chrome console and it appears the responce is plain txt not XML

XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}

onabort: null

onerror: null

onload :null

onloadend:null

onloadstart:null

onprogress:null

onreadystatechange:ƒ ()

ontimeout:null

readyState:4

response:"<?xml version='1.0' encoding='utf8'?>\n<TESTS><TEST><TITLE>test 1</TITLE><RESULT>PASS</RESULT></TEST></TESTS>"

responseText:"<?xml version='1.0' encoding='utf8'?>\n<TESTS><TEST><TITLE>test 1</TITLE><RESULT>PASS</RESULT></TEST></TESTS>"

responseType:""

responseURL:"[login to view URL]"

responseXML:null

status:200

statusText:"OK"

timeout:0

upload:XMLHttpRequestUpload {onloadstart: null, onprogress: null, onabort: null, onerror: null, onload: null, …}

withCredentials:false

[[Prototype]]:XMLHttpRequest

the Python script generating the XML isfrom flask import Flask, request, render_template

______________________________________________________________________________

import [login to view URL] as ET

import [login to view URL]

import os

app = Flask(__name__, template_folder='template')

[login to view URL] = True

xml_doc = [login to view URL]('TESTS')

test = [login to view URL](xml_doc,'TEST')

[login to view URL](test,'TITLE').text = 'test 1'

[login to view URL](test,'RESULT').text = 'PASS'

#xml_str = [login to view URL](xml_doc, encoding='utf8')

xml_str = [login to view URL]([login to view URL](xml_doc)).toprettyxml()

xml_str = [login to view URL]([s for s in [login to view URL]() if [login to view URL]()])

@[login to view URL]("/", methods=['GET', 'POST'])

def index():

#if [login to view URL] == "POST":

#name = [login to view URL]["name"]

#return '<?xml version="1.0" encoding="UTF-8"?>'+xml_str

#return xml_str

return render_template("[login to view URL]")

@[login to view URL]('/test_log')

def test_log():

return xml_str

if __name__ == "__main__":

[login to view URL](debug=True, host='0.0.0.0')

____________________________________________________________________

and the HTML is

____________________________________________________________________

<!DOCTYPE html>

<html>

<head>

<title>Practice AJAX</title>

<script type="text/javascript">

function myFunction(xml) {

var i;

var xmlDoc = [login to view URL];

[login to view URL](xml);

[login to view URL]([login to view URL]);

[login to view URL]("start1");

var table="<tr><th>Test</th><th>Result</th></tr>";

[login to view URL]("start2");

var x = [login to view URL]("test");

alert("process XML");

for (i = 0; i <[login to view URL]; i++) {

table += "<tr><td>" +

x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +

"</td><td>" +

x[i].getElementsByTagName("RESULT")[0].childNodes[0].nodeValue +

"</td></tr>";

}

[login to view URL]("demo").innerHTML = table;

}

function do_ajax() {

var req = new XMLHttpRequest();

var result = [login to view URL]('result');

[login to view URL] = function()

{

if([login to view URL] == 4 && [login to view URL] == 200) {

myFunction(this);

//[login to view URL]("demo").innerHTML = [login to view URL];

} else {

[login to view URL] = "Processing...";

}

}

[login to view URL]('GET', '/test_log', true);

[login to view URL]();

}

setInterval(do_ajax,1000);

</script>

</head>

<body>

<h1 id="DeviceID">Test Jig</h1>

<table>

<tr>

<th>Serial Number</th>

<th id=SerialHeader>0000</th>

</tr>

<tr>

<td>Alfreds Futterkiste</td>

<td>Maria Anders</td>

<td>Germany</td>

</table>

<br><br>

<table id="demo"></table>

<form action="index" method="post">

<label>Name:<input type="text" id="name" value="" /></label>

<button type="button" id="btn-post" onclick="do_ajax();">Click</button>

<div id="result"></div>

</form>

</body>

</html>

JavaScript AJAX

Nº del proyecto: #37067919

Sobre el proyecto

1 propuesta Proyecto remoto Activo hace 8 meses

Adjudicado a:

Mrdennyford

Hello, I'm a skilled full stack developer with expertise in HTML, CSS, JavaScript, React, Node.js, Angular.js, Diango and MongoDB. I can build your web application with a responsive design, user-friendly interface, an Más

$22 NZD en 7 días
(1 comentario)
0.9