使用java脚本调用Web服务方法时出错。
我想使用网络服务& amp; Java的脚本。请帮忙
<script src="../js/jquery-1.9.0.js" type="text/javascript"></script>
<script type="text/javascript">
function displayMessageCall() {
//alert("asd");
$.ajax({
type: "POST",
contentType: "application/json",
url: "http://domain.com.com/demo.asmx/InsertData",
data: "{ sUserName: 'Aidy', sEmailId: 'F' }",
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
function successMsg(response) {
alert('Success');
}
function errorMsg(response) {
alert(response.status + " " + response.statusText)
}
</script>
我使用了代码来调用Web服务方法
[WebMethod]
public static string InsertData(string sUserName, string sEmailId)
{
string sResult = string.Empty;
try
{
sResult = ExecuteScalar("INSERT INTO vg_demo(UserName, EmailId)VALUES('" + sUserName + "','" + sEmailId + "')").ToString();
}
catch
{
sResult = "101";
}
return sResult;
}
public static string ExecuteScalar(string sQuery)
{
string sValue = string.Empty;
SqlCommand oCommand;
try
{
SqlConnection oConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MySite"].ConnectionString);
oCommand = new SqlCommand(sQuery, oConnection);
oCommand.CommandType = CommandType.Text;
using (oConnection)
{
oConnection.Open();
sValue = Convert.ToString(oCommand.ExecuteScalar());
}
}
catch (Exception ex)
{
ApplicationError.LogErrors(ex);
}
return sValue;
}
我从errermsg函数得到0错误