Tôi đang cố gắng sử dụng giao diện người dùng jQuery tự động hoàn thành để kết hợp với một dịch vụ web với JSON phản hồi, nhưng tôi không thể làm như vậy.JSON và jQuery.ajax
Dịch vụ web của tôi thậm chí không được thực thi, đường dẫn phải chính xác vì thông báo lỗi không phàn nàn về điều này.
Điều gì gây ấn tượng với tôi là tiêu đề, phản hồi là xà phòng nhưng yêu cầu là json, nó có phải là như thế này không?
Response Headersvisa källkod
Content-Type application/soap+xml; charset=utf-8
Request Headersvisa källkod
Accept application/json, text/javascript, */*
Content-Type application/json; charset=utf-8
Thông báo lỗi tôi nhận được là như sau (xin lỗi vì thông điệp rất lớn, nhưng nó có thể là quan trọng):
xà phòng: ReceiverSystem.Web.Services.Protocols.SoapException: Server đã không thể yêu cầu quy trình. --- > System.Xml.XmlException: Dữ liệu ở cấp cơ sở không hợp lệ. Dòng 1, vị trí 1. tại System.Xml.XmlTextReaderImpl.Throw (Ngoại lệ e) tại System.Xml.XmlTextReaderImpl.Throw (Chuỗi res, String arg) tại System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() tại Hệ thống. Xml.XmlTextReaderImpl.ParseDocumentContent() tại System.Xml.XmlTextReaderImpl.Read() tại System.Xml.XmlTextReader.Read() tại System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read() tại hệ thống. Xml.XmlReader.MoveToContent() tại System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent() tại System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() tại System.Web.Services.Protocols.Soap12Serve rProtocolHelper.RouteRequest() tại System.Web.Services.Protocols.SoapServerProtocol.RouteRequest (SoapServerMessage message) tại System.Web.Services.Protocols.SoapServerProtocol.Initialize() tại System.Web.Services.Protocols.ServerProtocolFactory.Create (Type type, HttpContext bối cảnh, HttpRequest yêu cầu, HttpResponse đáp lại, Boolean & abortProcessing) --- End của nội ngoại lệ stack trace ---
Đây là mã của tôi:
$('selector').autocomplete({
source: function(request, response) {
$.ajax({
url: "../WebService/Member.asmx",
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({prefixText: request.term}),
success: function(data) {
alert('success');
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('error');
}
})
},
minLength: 1,
select: function(event, ui) {
}
});
Và vẻ webservice của tôi như thế này:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Member : WebService
{
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] GetMembers(string prefixText)
{
code code code
}
}
Tôi đang làm gì sai? Cảm ơn trước :)
Ofcourse !! Tôi không thể tin rằng tôi đã bỏ lỡ điều đó, tôi xin lỗi vì đã không nhận ra điều đó trước khi tôi đặt câu hỏi .. Cảm ơn câu trả lời của bạn! – Andreas
Không phải là một vấn đề, vui lòng giúp đỡ! Đó là những sai lầm nhỏ và rõ ràng mà mất nhiều thời gian nhất để chụp ảnh rắc rối! – Paul