FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

jQuery and Ajax problem

 


Fire Boar
If you know about jQuery, could you have a look at this for me please?

Code:
function doAll()
{
   var data = getQueryString(); // Gets anything on the url, I haven't posted this function here because I know it works
   var urlToUse = "process.php";
   if (data['name'] != null)
   {
      urlToUse = urlToUse + "?name=" + data['name'];
      if (data['file'] != null)
      {
         urlToUse = urlToUse + "&file=" + data['file'];
      }
   }
// The function convertToString is again written elsewhere. It works fine.
   $.ajax({
      type: "POST",
      dataType: "xml",
      url: urlToUse,
      data: convertToString(data),
      success: function(xml)
      {
         var comp;
         $('component', xml).each(function(id) {
         comp = $('component', xml).get(id);
         alert (comp);
         $('#component').text(comp);
         });
      }
   });
}


That function is called by $(document).ready. I have confirmed that it has been called (because of alerts). And it seems to be recieving the xml document properly as well. Unfortunately, from this line:

Code:
$('component', xml).each(function(id) {


Nothing seems to be happening (as in... "alert" fails). The XML file looks a bit like this:

Code:
<proc>
   <component>
      (some html)
   </component>
(some more values that I'll be using later on)
</proc>


The idea is I want it to get the HTML from inside the <component> tags and display it within <div id="component"></div>.

If anyone could help, I'd really appreciate it.
Fire Boar
Well, after tearing my hair out over this for several hours, I have managed to get solve this problem. But now there is a new problem. The HTML is coming out as entities rather than raw text. For example, instead of <table> we have &lt;table&gt;. I'm not sure whether this is XML or javascript that is putting them in, so I'll show you the relevant source.

The XML looks like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="includes/parse.xsl"?>
<proc>
   <component>
      <![CDATA[<table><tr><td>Test</td></tr></table>]]>
   </component>
</proc>


includes/parse.xsl looks like this:

Code:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="component">
      <xsl:value-of select="." disable-output-escaping="yes" />
   </xsl:template>
</xsl:stylesheet>


And the javascript success function for ajax is as follows:

Code:
   var comp;
   $(xml).find('component').each(function()
   {
      comp = $(this).text();
      $('#component').text(comp);
   });


Thanks if you can help. Smile
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.