I’m going to use a series of scripts like the one below to allow visitors to view lists of countries. For example, they can click on buttons labeled “North America,” “Africa,” etc. to see a list of countries associated with each continent.
<head>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("#driver").click(function(event){
$.get(
"/2b/inc/content/db-lists/world/lam.php",
{ name: "Zara" },
function(data) {
$('#div-lam7').html(data);
}
);
});
});
</script>
</head>
<body>
<input type = "button" id = "driver" value = "Latin America" class="btn" style="width: 100%; margin-top: 5px; background: #3c3; color: #fff; font-weight: 800;" />
<div id = "div-lam7" style = "background-color:cc0;">
</div>
</body>
But things could get a little confusing if a visitor winds up with half a dozen lists of countries displayed at once. Can anyone tell me how to modify my script so that users will be able to close a particular “window” or AJAX element?
After Googling for some help, it looks like I need to use one of these:
window.close();
$("#driver").dialog("close");
However, I haven’t been able to make either one work with my script. Most tutorials/examples show them associated with a “success” function, which apparently wasn’t part of the tutorial I got my AJAX script from.
Another question: I discovered that my AJAX function doesn’t work if the file containing the text I want to display is inside a folder that contains a capital letter. I simply fixed it by creating a new folder, with a lower-case name.
But I’m curious - Is AJAX case-sensitive? Otherwise, I have a script in my .htaccess file that nixes capital letters in URL’s, so maybe that’s the culprit.
Hi there, this looks like it’s only part of the script but I’ll give it a shot.
Can anyone tell me how to modify my script so that users will be able to close a particular “window” or AJAX element?
Your AJAX query is putting content into #div-lam7 so to clear it again you can simply do:
$('#div-lam7').html('');
URL’s are case sensitive, it’s up to your server to respond to things correctly, JavaScript doesn’t care what url’s you use. Still, it’s best practice to use lowercase letters only for directories and filenames.