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
https://forums.phpfreaks.com/topic/166342-solved-jquery-ajax-xml-help/
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.

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.