Reputation: 4914
I decided to dive into AJAX with help of jQuery, and I'm stuck already...
Anyway! I have a php file, that when called produces the following XML:
<response>
<status>1</status>
<character><charname>Loupax</charname>
<charId>112</charId>
<charLvl>1</charLvl>
<charStats>
<statsId>63</statsId>
<strength>13</strength>
<dexterity>14</dexterity>
<physique>15</physique>
<defence>12</defence>
</charStats>
</character>
</response>
What I want to do, is to display these elements on my html page (duh!) but I can't figure out the jQuery...
my jQuery is this:
$(document).ready(function(){
$("#showBtn").mouseup(function(){
var charname=$("#showInp").val();
//var data="";
$.ajax({
url: 'ajaxgetchar.php',
data: "showInp=Loupax",
dataType:text,
type:'POST',
success: function(data){
$('.result').xml(data);
alert("Success!!!");
};
});
});
});
and the markup is
<input type="button" value="Show character" id="showBtn" name="showBtn"/>
The problem is that, no matter how many times I click the button, I don't get the alert I was supposed to get...
Any help would be appreciated... I'm a total newb in XML/jQuery/ajax, and I'm pretty sure it's something dumb... :(
Upvotes: 0
Views: 110
Reputation: 513
First, I'd use $("#showBtn").click()
instead of $("#showBtn").mouseup()
. Second, you should remove the extra ;
after the success function. Third, download the Firebug extension for Firefox to see if it's actually making the ajax call and if so what the response is. If you get an error response code then the success function won't be called. To catch the error use the error(XMLHttpRequest, textStatus, errorThrown)
setting in your ajax call:
$.ajax({
url: 'ajaxgetchar.php',
data: "showInp=Loupax",
dataType:text,
type:'POST',
error: function(xhr, status, error){
// Handle error here
},
success: function(data){
$('.result').xml(data);
alert("Success!!!");
}
});
Upvotes: 1
Reputation: 19380
.xml method doesn't exist?
try
$('.result').text(data);
Also try alert(data), to see if it even returns anything.
$("#showBtn").click(function() {
$.ajax({
type: "POST",
url: "ajaxgetchar.php",
data: "showInp=Loupax",
success: function(data){
alert(data);
}
});
});
Upvotes: 1
Reputation: 7412
so it seems like you're getting an error, add an error: function(request, status, errthrown) { alert(errthrown); } to your code to see what the error is being thrown. You might need to adjust that function, I'm just doing it quickly from memory..
more details jQuery.ajax:
Upvotes: 0