Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript arrays

    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.

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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:
    Code:
    <!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
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •