This is my webmethod:
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
And this is the AJAX code in html page:
jQuery.support.cors = true;
var btn_startOp = document.getElementById("startOpp");
$.ajax({
type: "POST",
contentType: "application/xml; charset=utf-8",
data: "{}",
dataType: "xml",
url: "http://localhost:61457/WebSite1/Service.asmx/HelloWorld",
success: function(msg){ alert(msg.d); },
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
This is giving me an error : On,
Webservice is working fine when tested on browser.
UPDATE: This is the line in head tag in Html:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
Can anyone help me with this? This is the very first code for me..I searched a lot still its a mystery for me ... :) :(
Change to this:
$.ajax({
type: "GET",
url: "/WebSite1/Service.asmx/HelloWorld",
dataType:"json",
success: function(msg) {
alert(msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
dataType:"xml"
isn't required.GET
request.