Reputation: 109
Main.php
<!DOCTYPE html>
<html>
<head>
<title>Lesson 21: Easy AJAX Calls with jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
</head>
<body>
<h1>Lesson 21: Easy AJAX Calls with jQuery load()</h1>
<p><a href="#">Click here to fetch HTML content</a></p>
<div id="result">
</div>
<script type="text/javascript">
$(document).ready(function()
{
var url = "lesson18_test.xml";
function processData(data)
{
var resultStr = "";
var items = $(data).find('language');
$(items).each(function(i)
{
resultStr += $(this).text() + '<br />';
$('#result').html(resultStr);
});
}
$('a').click(function()
{
$.get(url, processData);
});
});
</script>
</body>
</html>
lesson18_test.xml
<?xml version="1.0" ?>
<languages>
<language>PHP</language>
<language>Ruby On Rails</language>
<language>C#</language>
<language>JavaScript</language>
</languages>
Above code is from one tutorial here: http://www.html.net/tutorials/javascript/lesson21.php
Question:
Is there a way that i can see the content in data? I tried alert(data)
, it only shows ' object XMLobject'. I know inside data is the lesson18_test.xml, but just want to see how it structured in data.
Upvotes: 0
Views: 116
Reputation: 1257
You may find the usage of $.ajax easier (I do, offers more freedom customizing it, matter of personal preference):
http://api.jquery.com/jQuery.ajax/
$.ajax(
{
type: "POST",
url: "/asdfasdf",
data: "foo=bar&name=cookiemonster",
// alternatively: data: { foo: "bar", name: "cookiemonster" },
timeout: 5000, /* 5sec */
success: function(data)
{
},
error: function(fa,il,ure)
{
// yay error handler
alert(fa + "\n" + il + "\n" + ure);
},
statuscode: { 404: function() { alert('Not found'); /* another way to handle errors */ }
});
Upvotes: 2
Reputation: 388316
Use the jqXHR object to get responseXML
or responseText
properties as given below
$(document).ready(function() {
var url = "lesson18_test.xml";
function processData(data, textStatus, jqXHR ) {
alert(jqXHR.responseText);
console.log(jqXHR.responseText)
var resultStr = "";
var items = $(data).find('language');
$(items).each(function(i)
{
resultStr += $(this).text() + '<br />';
$('#result').html(resultStr);
});
}
$('a').click(function()
{
$.get(url, processData);
});
});
Upvotes: 0
Reputation: 13535
Try alert(data.responsetext)
this will show you the data without being constructed to an object
Upvotes: 0