schilly Posted July 17, 2009 Share Posted July 17, 2009 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. Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 hmmmm ok. seems to be something in my php file when outputting the xml. Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 <?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. Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 <?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. Quote Link to comment Share on other sites More sharing options...
schilly Posted July 17, 2009 Author Share Posted July 17, 2009 didn't know xml tags need to be nested. fixed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.