I am new in jquery and trying to consume asp.net 3.5 made webservice in Jquery but i don't know why i can't use it. all the examples that i found over the internet are same as i'm doing, but i don't know whats happening to the code,
can anybody please help me ?
here is my javascript code,
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<test xmlns="http://tempuri.org/"> \
<param>this is a test parameter</param> \
</test> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: "http://localhost:50575/Service1.asmx?op=test",
type: "POST",
dataType: "xml",
data: soapMessage,
complete: hi,
error: function (a, b, c) {
alert("error");
},
contentType: "text/xml; charset=\"utf-8\""
});
function hi(xmlHttpRequest, status) {
alert($(xmlHttpRequest.responseText).text());
alert($(xmlHttpRequest.responseXML).find('Mymessage').text());
}
and here is server side code
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public message test(string param)
{
message mymsg = new message();
mymsg.head = "message head";
mymsg.Mymessage = "Test string with param " + param;
return mymsg;
}
The first object passed to the error handler should contain some useful information. Try to "expand" a in whatever debugging tool you're using. Don't just 'alert' its value.
Specifically, look for a.status
and a.responseText
. This should give you a good idea of what's going on.
我建议您尝试一下Fiddler ,这是一个出色的Web调试工具,应该可以帮助您发现问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.