Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7715745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:27:52+00:00 2026-06-01T02:27:52+00:00

I’m trying to do a simple exercise querying a database from JS using XMLHTTPrequest

  • 0

I’m trying to do a simple exercise querying a database from JS using XMLHTTPrequest Object and POST method. Basically I pass a string to PHP server, it recieves it, queries DB and returns an XML from where I read the information with JS, but something is not working: the callback function that should be executed after request is ready.

Here’s the JS code:

function leerDNI(dni){

var params="dni="+dni;

downloadUrl(params,"genxml.php", function(data) {
    var xml = parseXml(data);//THIS IS NOT BEING EXECUTED
    var dnis = xml.documentElement.getElementsByTagName("dni");//THIS IS NOT BEING EXECUTED
    for (var i = 0; i < dnis.length; i++) {//THIS IS NOT BEING EXECUTED
    var name = dnis[i].getAttribute("name");
    alert(name); //THIS IS NOT BEING EXECUTED
    document.getElementById("name").value=name; //THIS IS NOT BEING EXECUTED
 }
 });

 }

function downloadUrl(params,url, callback) {
 var request = window.ActiveXObject ?
 new ActiveXObject('Microsoft.XMLHTTP') :
 new XMLHttpRequest; 

request.onreadystatechange = function() {
 if (request.readyState == 4) {
 request.onreadystatechange = doNothing;
 callback(request.responseText, request.status);

 }
 };
 request.open("POST", url, true);
 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");//creación de headers
 request.send(params);//enviamos la petición POST
}

function parseXml(str) {
 if (window.ActiveXObject) {
 var doc = new ActiveXObject('Microsoft.XMLDOM');
 doc.loadXML(str);
 return doc;
 } else if (window.DOMParser) {
 return (new DOMParser).parseFromString(str, 'text/xml');
 }
}

function doNothing() {}  

The XML is being generated correctly. Anyone can light me up with what’s wrong in my code? Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:27:54+00:00Added an answer on June 1, 2026 at 2:27 am

    I’ve solved the issue, it was this line:

    var dnis = xml.documentElement.getElementsByTagName("dni");
    

    That was supossed to be substituted for:

    var dnis = xml.documentElement.getElementsByTagName("persona");
    

    Because I was generating persona nodes.

    Thanks for your answers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.