Jump to content

[SOLVED] jquery ajax xml help


schilly

Recommended Posts

So I've been pounding my head on this for a day now. I haven't had any problems using ajax in jquery up until now though it is the first time I've tried to get an xml response.

 

function addReview(){

		$.ajax({
	   		url: "ajax/add_review.php",
	   		dataType: "xml",
	   		type: "POST",
	   		data: $("#review_form").serialize(),
	   		success: function(msg){
alert("success");
			},
			error: function(xhr, ajaxOptions){
                                                        alert(xhr.status);
                                                        alert(xhr.statusText);
                                                 }
		});
		return false;
	}

So every time I run this it goes into the error callback and gives a 200 OK status message in the alerts. Firebug also says 200 OK code so I don't know why it won't go into the success callback. The xml response from the php files looks good too.

 

Any suggestions??

 

Thanks.

 

Link to comment
Share on other sites

<?php
header ("content-type: text/xml");

//make sure it was posted

$dom = new DomDocument('1.0');  

//add root - <books> 
$books = $dom->appendChild($dom->createElement('books')); 

//add <book> element to <books> 
$book = $books->appendChild($dom->createElement('book')); 

//add <title> element to <book> 
$title = $book->appendChild($dom->createElement('title')); 

//add <title> text node element to <title> 
$title->appendChild($dom->createTextNode('Great American Novel')); 

//generate xml 
$dom->formatOutput = true; // set the formatOutput attribute of 
                            // domDocument to true 
// save XML as string or file 
$test1 = $dom->saveXML(); // put string in test1 
//$dom->save('test1.xml'); // save as file 
echo $test1;
?>

ok this default examples give success msg but when I try to add my own xml it breaks.

Link to comment
Share on other sites

<?php
header ("content-type: text/xml");

//make sure it was posted

$dom = new DomDocument('1.0');  

//add root - <books> 
$books = $dom->appendChild($dom->createElement('books')); 

//add <book> element to <books> 
$book = $books->appendChild($dom->createElement('book')); 

//add <title> element to <book> 
$title = $book->appendChild($dom->createElement('title')); 

//add <title> text node element to <title> 
$title->appendChild($dom->createTextNode('Great American Novel')); 

//add my own line
$login = $dom->appendChild($dom->createElement('login'));

//generate xml 
$dom->formatOutput = true; // set the formatOutput attribute of 
                            // domDocument to true 
// save XML as string or file 
$test1 = $dom->saveXML(); // put string in test1 
//$dom->save('test1.xml'); // save as file 
echo $test1;
?>

ok added my own line and it broke.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.