0
Я написал простой HTML-страницы, как это:JQuery вебсервис вызов всегда по ошибке
<!DOCTYPE html>
<HTML>
<HEAD>
</HEAD>
<form name="form">
<input type="text" id="messageTest" name="msg" value="Your message"/>
<input type="submit" id="login" />
</form>
<script type="text/javascript" src="jquery.js"></script>
<script>
document.getElementById("login").addEventListener("click", function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "Test.asmx/HelloWorld",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function(xhr,err){
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
alert("responseText: "+xhr.responseText);
}
});
}, false);
</script>
</HTML>
Он всегда возвращается «readyState: 0 Статус: 0 responseText: неопределенные» Все мои файлы находятся в одной папке. Это мой вебсервис:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Test : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
Есть ли что-то я делаю не так?
что console.log (err); показывает в консоли? –
В нем отображается «ошибка». – Stan
См. Этот ответ. Возможно, это может быть то, что вам нужно: http://stackoverflow.com/a/11052049/1220550 –