[AJAX]Envoyer login et mot de passe avec la méthode POST?
J'ai suivi ce tutorial http://badger.developpez.com/tutorie...c-wcf-3-5/#LIV
Dans la partie client Javascript j'ai adapté le code de supprimer un film à mon cas d'utilisation et j'ai essayé ce code et tout va bien en passant le login et mot de passe d'authentification dans l'url dans la méthode open.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
<html>
<head>
<title>JQuery Easy XML Read Example</title>
<script type="text/javascript" charset="utf-8" src="js/Config/phonegap-0.9.3.js"></script>
<link rel="stylesheet" href="css/jquery/jquery.mobile-1.0a1.min.css" />
<link rel="stylesheet" href="css/Style.css" />
<script src="js/Config/jquery-1.4.3.min.js"></script>
<script src="js/Config/jquery.mobile-1.0a1.min.js"></script>
<script language="javascript">
function ButtonDELETE_onclick() {
var ws_key="mon_login";
var PHP_AUTH_USER="mon_motdepasse";
var xmldelete = new XMLHttpRequest();
if(!xmldelete){ return; }
xmldelete.onreadystatechange = function()
{
if(xmldelete.readyState == 4)
{
if(xmldelete.status == 200)
alert("client effacé");
else
alert("Error code " + xmldelete.status);
}
};
xmldelete.open("DELETE", "http://patisserie-orient.fr/prestashop/prestashop/api/customers/6?PHP_AUTH_USER="+PHP_AUTH_USER+"&ws_key="+ws_key, true);
xmldelete.send(null);
}
</script>
</head>
<body>
<input type="button" value="ok" onclick="ButtonDELETE_onclick()"/>
</body>
</html> |
Puis je viens de tester le code d'ajout d'un film donc le probléme se déclenche là.
J'ai besoin d'envoyer le login et le mot de passe d'authentification, mais la méthode POST ne les accépte pas dans l'url.
Comment puis-je les envoyer?
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PhoneGap</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" charset="utf-8" src="js/Config/phonegap-0.9.3.js"></script>
<script src="js/Config/jquery-1.4.3.min.js"></script>
<script src="js/Config/jquery.mobile-1.0a1.min.js"></script>
<script src="jquery.form.js"></script>
<script language="javascript">
function on()
{
var ws_key="mon_login";
var PHP_AUTH_USER="mon_motdepasse";
var xmlpost =new XMLHttpRequest();
if(!xmlpost){ return; }
var postdata = document.getElementById("TextAreaPOST").value;
alert(postdata);
xmlpost.onreadystatechange = function()
{
if(xmlpost.readyState == 4)
{
alert(xmlpost.status);
if(xmlpost.status == 201)
{
alert(xmlpost.getResponseHeader("Location"));
}
else
alert("Error code " + xmlpost.status + xmlpost.statusText);
}
};
xmlpost.open("POST", "http://patisserie-orient.fr/prestashop/prestashop/api/customers", true);
xmlpost.setRequestHeader('Content-Type', 'text/xml');
xmlpost.send(postdata);
}
</script>
</head>
<body>
<div id="test" />
<input type="text" id="TextAreaPOST" name="TextAreaPOST" value='passwd="043a2471c34a84d8f731caadd327d65egg"&lastname="nom"&firstname="prenom"&email="monemail@gmail.com"'/><br>
<input type="button" value="ok" name="bbb" id="bbb" onclick="on()">
</body>
</html> |