0

From 1st page I pass 2 parameters http://in164263:5050/csm/csminfo.jsp?cfgid=48&filepath=files/csmclientbuckeye.xml

How to read the request parameter in csminfo.jsp and get xml file from filepath?

I suppose for reading and parsing xml I can us something like this

$.ajax({
    type: "GET",
    url: "sites.xml", //here i want to read request parameter `filepath`
    dataType: "xml",
    success: function(xml) {

    }
});

The problem is i am passing the filepathon onLoad of page's body, so the spry region tries to load itself through the dataset(which is not yet initialised) but since it does not have the path yet it is not displayed. So how can I get the filepath before onLoad so that spry:region gets this filepath?

AabinGunz
  • 12,109
  • 54
  • 146
  • 218

2 Answers2

0

You can use jQuery.ajax() with dataType set to XML if the server, from which you are fetching data doesn't send proper content-type. Then in success callback first argument is your XML.

 $.ajax('path/xml', {
   success: function(xml) {
     var $xml = $(xml);
     alert($xml.find( "title" ));
   }
 });

Or use jQuery.parseXML inside success callback.

aambrozkiewicz
  • 542
  • 3
  • 14
  • The path to the xml file is coming from previous page as url variable, how can i access that variable in jquery? – AabinGunz Jun 15 '11 at 08:26
0

With JSP you can use something like this to setup properly your ajax call

$.ajax({
    type: "GET",
    url: "<%= request.getParameter("filepath") %>",
    dataType: "xml",
    success: function(xml) {

    }
});

Otherwise, if you really NEED to read the get or post parameters via javascript (jQuery), you can follow this answer : how to get GET and POST variables with JQuery?

Community
  • 1
  • 1
VAShhh
  • 3,494
  • 2
  • 24
  • 37
  • Not happening `url: "<%= request.getParameter('filepath') %>"` is not able to read the file – AabinGunz Jun 15 '11 at 08:41
  • Once that your JSP page is parsed / loaded (in the browser) you should see `url : "files/csmclientbuckeye.xml"`, what do you see? – VAShhh Jun 15 '11 at 08:45
  • Check these examples http://www.exampledepot.com/egs/javax.servlet.jsp/getparam.html to get rid of the `getParameter` method – VAShhh Jun 15 '11 at 08:46
  • before using this reading xml, I was passing my req params to a function where i was able to fetch `files/csmclientbuckeye.xml` from `filepath` this is what i was using `','<%= request.getParameter("filepath") %>')">` so `"<%= request.getParameter('filepath') %>"` should get me the path, but is not working – AabinGunz Jun 15 '11 at 08:48
  • Can this be a apex problem? i mean, why are you using `"<%= request.getParameter('filepath') %>"` and not `"<%= request.getParameter("filepath") %>"` ? JSP should parse only the text inside the `<%` and `%>` and ignore the rest – VAShhh Jun 15 '11 at 08:54