my ajax function is triggered on window.load but it doesn't affect html at all. Here's my ajax: - function titleTopic(url)
-
{
-
var xmlhttp;
-
var txt,txt2,xxx,xx,x;
-
if (window.XMLHttpRequest)
-
{// code for IE7+, Firefox, Chrome, Opera, Safari
-
xmlhttp=new XMLHttpRequest();
-
}
-
else
-
{// code for IE6, IE5
-
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
xmlhttp.onreadystatechange=function()
-
{
-
if (xmlhttp.readyState==4 && xmlhttp.status==200)
-
{
-
x=xmlhttp.responseXML.documentElement.getElementsByTagName("ARTICLE");
-
-
xx=x[0].getElementsByTagName("TITLE");
-
txt=xx[0].firstChild.nodeValue;
-
xxx=x[0].getElementsByTagName("AUTHOR");
-
txt2=xxx[0].firstChild.nodeValue;
-
-
-
document.getElementByTagName('h3').innerHTML=txt;
-
document.getElementByTagName('span').innerHTML=txt2;
-
}
-
}
-
xmlhttp.open("GET",url,true);
-
xmlhttp.send();
-
}
10 2766
How do you know it triggers?
On line 25 and 26, it's getElementsByTagName, not getElementByTagName.
Yeah ive changed the code but it still doesn't work, ive runthe website on google console and the errors ive got are
Uncaught SyntaxError: Unexpected end of input for line 1 of moje.js
Uncaught ReferenceError: process is not defined for line 71 of webdesign.html which is basically the button with process() function
So it's basically the first line of my javascript file: var xmlHttp = createXmlHttpRequestObject();
and then a button that triggers my function in html
my full ajax: - var xmlHttp = createXmlHttpRequestObject();
-
-
//create object
-
function createXmlHttpRequestObject() {
-
var xmlHttp;
-
if (window.XMLHttpRequest){
-
xmlHttp = new XLHttpRequest();
-
} else {
-
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
return xmlHttp;
-
}
-
-
//called onload
-
-
function process() {
-
if(xmlHttp) {
-
try{
-
xmlHttp.open("GET", "C:/xampp/htdocs/webdesign.xml", true);
-
xmlHttp.onreadystatechange = handleStateChange;
-
xmlHttp.send(null);
-
}
-
catch(e) {
-
alert(e.toString());
-
}
-
}
-
-
//when state changes
-
function handleStateChanges() {
-
if (xmlHttp.readyState==4) {
-
if(xmlHttp.status==200) {
-
try {
-
handleResponse();
-
-
}
-
catch(e) {
-
alert(e.toString());
-
}
-
} else {
-
alert(xmlHttp.statusText);
-
}
-
}
-
}
-
//handle the response from the server
-
function handleResponse() {
-
var xmlResponse = xmlHttp.responseXML;
-
root = xmlResponse.documentElement;
-
articles = root.getElementsByTagName("TITLE");
-
authors = root.getElementsByTagName("AUTHOR");
-
-
var stuff = "";
-
for (var i=0; i<articles.length; i++) {
-
stuff = articles.item(i).firstChild.data + " - " + authors.item(i).firstChild.data + "<br/>";
-
-
}
-
super2 = document.getElementByID("super2");
-
super2.innerHtml = stuff;
-
}
-
-
and the mentioned html - <article id='super2'>
-
<button onclick="process()">Get XML data</button>
-
-
</article>
The first error that jumps out at me is that on line 7 of your javascript code block, XLHttpRequest should be XMLHttpRequest
oh you're right, fixed it but it still doesn't work
I'm using xampp but ajax is just ignored other javascript works just fine.
Still im getting the same error from the console
Uncaught ReferenceError: process is not defined webdesign.html:71
onclick
ok, i kind of made stupid mistake and fixed it, i lacked one curly bracket that's it and started getting error alerts
but i get an error from xml I found it and fixed it but it's still the same: - <?xml version="1.0" encoding="ISO-8859-1"?>
-
<!-- Edited by XMLSpy® -->
-
<RESPONSE>
-
<TOPICS>
-
<ARTICLE>
-
<TITLE>The Lean UX Manifesto: Principle-Driven Design</TITLE>
-
<AUTHOR>Anthony Viviano</AUTHOR>
-
<YEAR>2014</YEAR>
-
<TEXT>My colleague Ajay and I have been working at incorporating lean UX at the enterprise level for over two years. In studying it, I find that there is a temptation to lay down rules, and if the rules arent followed. well, then, you cant call it lean UX. At the end of the day, though, some lean UX is better than none.</TEXT>
-
</ARTICLE>
-
<ARTICLE>
-
<TITLE>Killer Responsive Layouts With CSS Regions</TITLE>
-
<AUTHOR>CJ Gammon</AUTHOR>
-
<YEAR>2013</YEAR>
-
<TEXT>As Web designers, we are largely constrained by the layout features available to us. Content placed inside a container will often naturally extend the container vertically, wrapping the content. If a design requires elements to remain a certain height, then our options are limited. In these cases, we can only add a scroll bar or hide the overflow. The CSS Regions specification provides a new option.</TEXT>
-
</ARTICLE>
-
<ARTICLE>
-
<TITLE>Original And Innovative Web Layouts</TITLE>
-
<AUTHOR>Shavaughn Haack</AUTHOR>
-
<YEAR>2013</YEAR>
-
<TEXT>The layout is the foundation of your website. It guides the user through the sections and tells them what is most important. It also sets the aesthetic of the website. Therefore, you need to carefully think through how you lay out content.</TEXT>
-
</ARTICLE>
-
</TOPICS>
-
</RESPONSE>
XML Parsing Error: mismatched tag. Expected: </AUTHOR>. Location: moz-nullprincipal:{b3ef63a7-15a2-4c24-8903-7e94bdda5807} Line Number 16, Column 5:
</ARTICLE>
------------------^
Probably it's a stupid mistake too oh well..
Thx for your help anyway
it just hasn't updated the file, i fixed it but it's still not displaying anything
Where is the code getting stuck at now? And what's your newly modified code? It sounds like you made more than a few changes.
ok fixed it, i just needed a monologue i guess xD
Can you post your final solution? In case someone else runs into the same issue and stumbles upon this thread.
They were mostly typos of methods and one essential bracket was missing, final version: -
var xmlHttp = createXmlHttpRequestObject();
-
-
//create object
-
function createXmlHttpRequestObject() {
-
var xmlHttp;
-
if (window.XMLHttpRequest){
-
xmlHttp = new XMLHttpRequest();
-
} else {
-
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
return xmlHttp;
-
}
-
-
//called onload
-
-
function process() {
-
if(xmlHttp) {
-
try{
-
xmlHttp.open("GET", "webdesign1.xml", true);
-
xmlHttp.onreadystatechange = handleStateChange;
-
xmlHttp.send(null);
-
}
-
catch(e) {
-
alert(e.toString());
-
}
-
}
-
-
//when state changes
-
function handleStateChange() {
-
if (xmlHttp.readyState==4) {
-
if(xmlHttp.status==200) {
-
try {
-
handleResponse();
-
-
}
-
catch(e) {
-
alert(e.toString());
-
}
-
} else {
-
alert(xmlHttp.statusText);
-
}
-
}
-
}
-
//handle the response from the server
-
function handleResponse() {
-
var xmlResponse = xmlHttp.responseXML;
-
root = xmlResponse.documentElement;
-
articles = root.getElementsByTagName("TITLE");
-
authors = root.getElementsByTagName("AUTHOR");
-
-
var stuff = "";
-
for (var i=0; i<articles.length; i++) {
-
stuff = "<p>" + articles.item(i).firstChild.data + " - " + authors.item(i).firstChild.data + "</p>";
-
-
}
-
super2 = document.getElementById("super2");
-
super2.innerHTML = stuff;
-
}
-
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bruce A. Julseth |
last post by:
When I execute this SQL statement in my PHP code, I get an error
"File '.\Address.txt' not found (Errcode: 2)"
$File = addslashes(".\Address.txt");
$SQL = "Load Data InFile \"" . $File . "\"...
|
by: Alex Hunsley |
last post by:
I'm using a mysql monitor under cygwin (on win xp) to do a 'load data
infile' to put some data into a mysql database (I'm using the xampp
bundle)..
My problem is that I have a four line CSV file...
|
by: Kins |
last post by:
Hi,
In web application, I use listbox in the EditItemTemplate in the Datagrid.
But I cannot load data from the database to the Listbox.
Is it possible ? Thx a lot
regards,
Kin
|
by: Ray in HK |
last post by:
What are the differences between LOAD DATA INFILE and LOAD DATA LOCAL INFILE
?
I found some web hosting company do not allow using LOAD DATA INFILE but
allow LOAD DATA LOCAL INFILE. The reason...
|
by: Uthuras |
last post by:
Greetings,
Machine : Pentium IV
Os Windows 2000 server
Product : DB2 UDB Release : 7.2
We are fail to load the following data file format into db2 database
table that has long varchar...
|
by: thjwong |
last post by:
I'm using WinXP with Microsoft Visual C++ .NET
69462-006-3405781-18776, Microsoft Development Environment 2003 Version
7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1
Most developers...
|
by: Adrian Turner |
last post by:
I am just starting developing with .Net(Have used asp for years). I have
created a very simple upload page which once uploaded opens the file(excel)
and displays the data. If I Attempt to re-run...
|
by: Fendi Baba |
last post by:
I created an ASP.net page which opens excel. This works fine in Office
2007. However, Excel 2003 runs in an error which states "cannot read
output file".
Hee is the VB code and below is the ASPX...
|
by: =?Utf-8?B?VGVycmVuY2U=?= |
last post by:
For a past day or two I've been to noticing the following error.
Event Type: Warning
Event Source: Outlook
Event Category: None
Event ID: 25
Date: 6/24/2007
Time: 12:05:07 PM
User: N/A...
|
by: pzero24 |
last post by:
Ok so I am making plugins for my application and I have the plugins located in a subdirectory:
/AppDir
/AppDir/Plugins
All my plugins reference a Plugins interface file, which is also located...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |