Appel d'un web service en local avec html
amateur_gadget
Messages postés
29
Date d'inscription
Statut
Membre
Dernière intervention
-
amateur_gadget Messages postés 29 Date d'inscription Statut Membre Dernière intervention -
amateur_gadget Messages postés 29 Date d'inscription Statut Membre Dernière intervention -
Bonjour tout le monde,
J'essaie depuis 2 jours de faire un appel à mon web service en local en utilisant html et ajax mais j'arrive jamais je sais pas c'est quoi le problème pouvez vous m'aider en me donnant un exemple pour l'appel du helloworld service ? Mercii d'avance
J'essaie depuis 2 jours de faire un appel à mon web service en local en utilisant html et ajax mais j'arrive jamais je sais pas c'est quoi le problème pouvez vous m'aider en me donnant un exemple pour l'appel du helloworld service ? Mercii d'avance
A voir également:
- Appel d'un web service en local avec html
- Appdata local - Guide
- Web office - Guide
- Nommez une application d'appel vidéo ou de visioconférence - Guide
- Service spouleur - Guide
- Appel privé - Guide
1 réponse
Ok bien sur supposons que mon web service helloworld a comme adresse http://localhost:2049/HelloWorld/hello.asmx et sa réponse est sur l'adresse http://localhost:2049/HelloWorld/hello.asmx/HelloWorld mon code est :
<html>
<head>
<script>
function submitForm()
{
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{ var doc = xhr.responseXML;
var element = doc.getElementsByTagName('root').item(0);
if(xhr.status == 200)
document.ajax.dyn.value= element.firstChild.data;
else
document.ajax.dyn.value= element.firstChild.data;
}
};
xhr.open( GET", "http://localhost:2049/HelloWorld/hello.asmx/HelloWorld", true);
xhr.send(null);
}
</script>
</head>
<body>
<FORM method="POST" name="ajax" action="http://localhost:2049/HelloWorld/hello.asmx">
<INPUT type="BUTTON" value="Submit" ONCLICK="submitForm()">
<INPUT type="text" name="dyn" value="">
</FORM>
</body>
</html>
<html>
<head>
<script>
function submitForm()
{
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{ var doc = xhr.responseXML;
var element = doc.getElementsByTagName('root').item(0);
if(xhr.status == 200)
document.ajax.dyn.value= element.firstChild.data;
else
document.ajax.dyn.value= element.firstChild.data;
}
};
xhr.open( GET", "http://localhost:2049/HelloWorld/hello.asmx/HelloWorld", true);
xhr.send(null);
}
</script>
</head>
<body>
<FORM method="POST" name="ajax" action="http://localhost:2049/HelloWorld/hello.asmx">
<INPUT type="BUTTON" value="Submit" ONCLICK="submitForm()">
<INPUT type="text" name="dyn" value="">
</FORM>
</body>
</html>