By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

How to reload a specific div of a page with XMLHTTP

P: 2
Hi,

I have a page (MainPage.aspx) that contains transformed XML data in different divs. The transformation is done in C# with an XML and an XSL file. The requirement is, based on user input , the xml should be updated which will update the page as well.

I have a javascript which takes the input from a input field from mainpage.aspx and sends to the C# code which updates the XML and reloads the page with the Updated XML data.

But I want to refresh only the div whose data is updated rather than the whole Page.

Can I use XMLHTTP request for reloading a specific div of the mainpage.aspx. If yes, is there any example which I can refer?

Appreciate any help.
Oct 23 '07 #1
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!
Can I use XMLHTTP request for reloading a specific div of the mainpage.aspx. If yes, is there any example which I can refer?
Yes, of course. See an example. Also check out the Ajax tutorial links in the Off-site Links thread.
Oct 23 '07 #2

P: 2
the problem I have here is the div contains some xml data and the div needs to be updated when there is an update in xml data.


Expand|Select|Wrap|Line Numbers
  1. xmlHttp.open("GET", url,true);
  2. var str=xmlHttp.responseText
  3.  document.getElementById(div).innerHTML = str;
  4.  
In the above code, we are passing the url of the page that contains the div. so str would contain the text that the whole page contains.And when we pass str to the div, it would display the whole page again in the div.

How can i extract the div from a page.so that i can passonly the div content to the div's innerHtml?
Oct 24 '07 #3

acoder
Expert Mod 15k+
P: 16,027
How can i extract the div from a page.so that i can passonly the div content to the div's innerHtml?
The best way would be to code your server-side script to only return the div and nothing else.

If, for some reason, that isn't possible or you don't wish to change that code, you will have to parse the response text for the div by using DOM methods, e.g. document.getElementById().
Oct 24 '07 #4

P: 2
Hi

How can I parse the response text. I dont want to pass the conent of the whole URL, rather I want to pass the contents of a div only.

Is there any example to refer? Thanks
Nov 14 '07 #5

acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!
Hi

How can I parse the response text. I dont want to pass the conent of the whole URL, rather I want to pass the contents of a div only.

Is there any example to refer? Thanks
Can you give an example of a response from the server and what you want to parse out from it.
Nov 14 '07 #6

P: 2
I have multiple divs in my page. Among them, the div "DivXMLContainer" populates some data from xml data. Now when I add some data to the xml, I want to refresh the div with the updated data.

When I use the xmlhttp.open(Get, URL), I pass the url of the page . Hence the xmlhttp.responsetext gets the whole page .

Now the following line would display the entire page's content inside the div.
document.getelementbyID.("DivXMLContainer").innerH TML= xmlhttp.responsetext


Is there any way , I can parse the 'DivXMLContainer' from the responsetext or is there any other way around?

Let me know if I need to put the XHTML code here.

Thanks
Nov 15 '07 #7

acoder
Expert Mod 15k+
P: 16,027
You could do using responseText.getElementsByTagName("div") and then checking the id.

However, wouldn't it be better to just do this on the server-side instead, i.e. let the server-side code just return the required XML, so there's no need to parse the data.
Nov 16 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.