Résolut probléme avec une recherche prédictive
bonjour, j'essaye dans mon site web asp.net de créé une recherche prédictive mais lorsque je la lance j'ai une erreur.
voici mon code
Default.aspx.cs
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
[System.Web.Services.WebMethod]
public static string GetRecherche(string recherche)
{
String[][] Entreprise = {
new string[] {"amazon.fr","france","http://www.amazon.fr/"},
new string[] {"amazon.co.jp","japon","http://www.amazon.co.jp/"},
new string[] {"amazon.com","us","http://www.amazon.com/"},
new string[] {"samsung.com","coré","http://www.samsung.com/fr/"}
};
};
string result = "";
for (int i = 0; i < Entreprise.Length; i++)
if (Entreprise[i][0].Contains(recherche))
result = result + "<tr><td>" + Entreprise[i][0] + "</td><td>" + Entreprise[i][1] + "</td><td><a href=\"" + Entreprise[i][2] + "\"> url </a></td></tr>";
return result;
} |
Default.aspx.cs
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
|
<script type="text/javascript">
$(document).ready(function () {
var $q = $('#q');
$($q).keyup(function () {
//alert($q.val());
if ($q.val().length > 2) {
var data = { 'recherche': $q.val() };
//alert(data.recherche);
$.ajax({
type: "POST",
url: "Default.aspx/GetRecherche",
async: false,
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (msg) {
// alert('lol');
$("#Result").html(msg.d);
},
error: function () { alert("Ajax Error"); }
})
}
});
});
</script>
<label for="q">Rechercher un article</label>
<input type="text" name="q" id="q" /> |
Et voici erreur que m'indique firedebug
POST http://localhost:50758/SiteFutSheet/...x/GetRecherche
401 Unauthorized
33ms
jquery....min.js (ligne 4)
En-têtesPostRéponseJSONCookies
{"Message":"Échec de l\u0027authentification.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
Merci d'avance pour votre aide