Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > AJAX

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-13-2009, 01:30 AM
vidhya vidhya is offline
Registered User
 
Join Date: Oct 2009
Posts: 2
ajax reload problem

Hi
I am new to ajax but i have done one simple menu program using ajax i created one index page with menus if i click each menu i want that linked page in the same window now i am getting as a separate window that is i want to refresh only that particular part and not the whole page i will give you the code that i have done please help me out

Code:
 this is my index.html page were i have my menus

<html>
<head>
<title>My ajax website</title>
<script language="javascript" type="text/javascript" src="ajax.js"></script>
</head>
<body>
<div id="nav">
<a href="home.html" onClick="sendRequest('home.html');">Home</a>
<a href="first.html"onClick="sendRequest('first.html');">First Page</a>
<a href="second.html onClick="sendRequest('second.html');">Second Page</a>
</div>
<br/>
<div id="content">
<script language="Javascript" type="text/javascript">
if ((window.location.href.split("#", 2)[1] == null) || (window.location.href.split("#", 2)[1] == "") || (window.location.href.split("#", 2)[1] == "index")){
sendRequest("index.html");
}else{
sendRequest(window.location.href.split("#", 2)[1] + ".html");
}
</script>
</div>
</body>
</html>

Code:
 ajax.js
function createRequestObject() {
	var req;

	if(window.XMLHttpRequest){
		// Firefox, Safari, Opera...
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		// Internet Explorer 5+
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		// There is an error creating the object,
		// just as an old browser is being used.
		alert('Problem creating the XMLHttpRequest object');
	}
	return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();

function sendRequest(webpage) {
	// Open PHP script for requests
	http.open('get', webpage);
	http.onreadystatechange = handleResponse;
	
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4 && http.status == 200){

		// Text returned FROM the PHP script
		var response = http.responseText;

		if(response) {
			// UPDATE ajaxTest content
			//alert(response);
			document.getElementById("content").innerHTML = response;
		}
	}
}
Reply With Quote
  #2  
Old 10-15-2009, 12:56 AM
jmajews1 jmajews1 is offline
Registered User
 
Join Date: Oct 2009
Posts: 3
Problem is in your anchor tag

Your reload problem is not due to your AJAX code, rather the anchor tags href. <a href="home.html" onclick="...."> when clicked will cause the current page to navigate to home.html.

Option 1: use href="#" instead of pointing to an external URL.

Option 2: don't use an anchor tag at all. Replace the <a> tag with a <span> tag.

Hope this helps.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with XML & AJAX kasei AJAX 1 11-12-2008 02:33 PM
Ajax browser and drop down menu problem blckspder AJAX 1 11-22-2006 04:19 PM
login problem dbrook007 ASP.NET 0 11-06-2006 05:54 AM
Problem while using AJAX inside frames Hariharan Java 0 07-05-2006 08:08 AM
Re: Thank you; weird problem with OleDb provider objects. Anyone have this problem? DK .NET 0 12-13-2001 01:06 PM


All times are GMT -4. The time now is 02:35 AM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.