Ajax & Webservice – Appeler un Webservice depuis javascript – remplissage d’un menu déroulant

 

<input
id=”Button1″
type=”button”
value=”button”
onclick=”getVille();”
/>


<select
id=”Select1″>

<option
value=”première”>première option</option>

</select>
var
xmlHttp;
function
getVille()
{
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”
);
xmlHttp.open(“POST”, http://localhost:2079/WebService1.asmx/Ville2&#8221;, true
);
xmlHttp.onreadystatechange = doUpdate;
xmlHttp.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”
);
xmlHttp.send();
return
false

;
}

function
doUpdate()
{ if
(xmlHttp.readyState == 4) {
var
xmlDoc = xmlHttp.responseXML;
var
i = 0;
x = xmlDoc.documentElement.childNodes;
while
(i < x.length){
var responseElement = xmlDoc.getElementsByTagName(“string”
)[i];
var respText = responseElement.firstChild.nodeValue;
document.getElementById(‘Select1’).options[i] = new
Option(respText, respText);
i++;
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s