0

I'm using AJAX on an ASP.NET web project to update a page. Some of my functions return XML that I want to embed on the page after it reloads. This part works, here's a sample of how it looks at the top of the page:

var productXML = "<?xml version=\"1.0\"?><ArrayOfProduct xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Product><ActualProdID>123</ActualProdID><Name>Test</Name><Description>Test</Description><Edition>Test</Edition><Platform>Test</Platform><Family>Test</Family><Type>Test</Type><DeploymentTypes>Test</DeploymentTypes><BaseActualProdID>Test</BaseActualProdID><Price>0</Price></Product></ArrayOfProduct>";

Later in the page I'm trying to use the XML but it's not working. I tried to do something simple and just throw an alert box in that looks like this:

<script type="text/javascript">
function closeLoading()
{
    jQuery('.pleaseWaitPanel').css({ 'display': 'none', 'visibility': 'hidden' });
    alert("here");
    alert(productXML);
    alert("here2");
}
</script>

closeLoading() is called inside:

window.onload = function () { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(closeLoading); };

It loads the jQuery and the first alert "here" works perfect. When I go to alert the productXML, nothing happens. It doesn't throw a JavaScript error, I'm using Firebug. I can confirm the XML is on the page.

Any help on this would be GREATLY appreciated!!

2 Answers 2

1

From your code snippets, it looks like your closeLoading function is only being called in your window.onload function. This means that it won't be called after any Ajax request completes as the window won't be reloaded.

I would try moving your call to Sys.WebForms.PageRequestManager.getInstance().add_endRequest(closeLoading) to just before your closing server-side form tag:

<form runat="server">
    ...
    <script>
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(closeLoading);
    </script>
</form>

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0
var productXML 

Is a ServerSide variable, so you don't have access to this in Client script.

If you want to use in a javascript function you can do this :

1) Put the result in a textbox hidden, like

<input type='hidden' value='<%=productXML%>'> 

then simply get the value of the textbox.

2 Comments

It's not server side, that's the javascript var I'm embedding on the page. It should be accessible client side since it does show up between <script type="text/javascript">var productXml="";</script>
Sorry.... I've tried your code (only the var declaration and the alert) and i see the alert... try to put the var declaration inside your function and see if it show up the alert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.