...

View Full Version : javascript arrays



kstriyhon
07-13-2005, 06:08 PM
i need to send a set of project names from a javascript web page to a C# web service using the url.
one option is get these project names into an array in order to make the URL shorter.

how can i send this string array?
do i have to serialize it?
or how can i send this set of names is there any other suggestion??
any help would be apreciate, thank's in advance.

martin_narg
08-08-2005, 01:37 PM
I'm assuming the array is less than 2k in size? If it is, you can pass it via a querystring using AJAX something like this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url) {
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
if(xmlhttp) {
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
}
}

function xmlhttpChange() {
if(xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
alert("updated");
} else {
alert("error sending data");
}
}
}

function sendMe() {
var a = ["foo", "bar", "tik", "wib"];
for(var i=0; a[i]; i++) {
a[i] = escape(a[i]);
}
var url = "http://www.myDomain.com/myWebService?"+a.join(",");

loadXMLDoc(url);
}
</script>
</head>

<body>
<input type="button" value="send array" onclick="sendMe();">
</body>
</html>


Hope this helps

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum