KeithMcElroy
asked on
asp return xml object?
Can I call a CLASSIC asp page from Jquery ajax and have the asp page return a parsable xml dom
object (instead of string) so that I can consume it in jquery using xml parsing?
If so, how would I code the asp page to return the object
response.write ???
object (instead of string) so that I can consume it in jquery using xml parsing?
If so, how would I code the asp page to return the object
response.write ???
Let's say you have a page called datapage.asp you post to via jquery. Create an empty div with a class called result. The data from the post to the external page will be placed in the empty div after the page loads.
jquery is javascript. Javascript runs after the page loads while your asp vb code runs before the page loads. This means the two don't talk directly to each other and jquery and parse anything you present in asp vb because that will be rendered as html, then the page loads and jquery takes over.
<div class="result"></div>
<script>
$.post('datapage.asp', function(data) {
$('.result').html(data);
});
</script>
jquery is javascript. Javascript runs after the page loads while your asp vb code runs before the page loads. This means the two don't talk directly to each other and jquery and parse anything you present in asp vb because that will be rendered as html, then the page loads and jquery takes over.
<div class="result"></div>
<script>
$.post('datapage.asp', function(data) {
$('.result').html(data);
});
</script>
Another option is to build up the xml in your asp code. Then render it, then have jquery do it's stuff.
<%
theXML=""
theXML=theXML&<color>red</ color>
theXML=theXML&<color>white </color>
theXML=theXML&<color>blue< /color>
response.write theXML
%>
<script>
//jquery code to parse xml
</script>
<%
theXML=""
theXML=theXML&<color>red</
theXML=theXML&<color>white
theXML=theXML&<color>blue<
response.write theXML
%>
<script>
//jquery code to parse xml
</script>
The simple answer is yes...
The next question is what would the ASP file look like.
First, it would NOT contain any JS, as indicated in some of the posts above, as this is XML to be consumed by JS/JQuery.
There are two ways of doing this. First, as mentioned by padas, build a string containing the data and response.write it.
Second, and more readable would be something like this:
... this could then have dynamic stuff added:
HTH
GH
The next question is what would the ASP file look like.
First, it would NOT contain any JS, as indicated in some of the posts above, as this is XML to be consumed by JS/JQuery.
There are two ways of doing this. First, as mentioned by padas, build a string containing the data and response.write it.
Second, and more readable would be something like this:
<xml>
<element>
<sub-element>
<item>Value</item>
<sub-element>
</element>
</xml>
... this could then have dynamic stuff added:
<xml>
<element>
<%for i = 1 to 10%>
<sub-element>
<item><%=i%></item>
<sub-element>
<%next%>
</element>
</xml>
HTH
GH
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
Then after you have done with creating/modifying it, you can send it to the client as text:Open in new window
or directly:Open in new window