jqueryui ダイアログ フォームで顧客が入力した値を ajax ポストを使用して webhandler (ashx) に送信しようとしていますが、成功しませんでした。以下のコードは次のとおりです。
Webhandler[login.ashx]
public class Login : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/json";
// string ID = context.Request.QueryString["ID"];
//Want to pass full name , email and selected value of dropdown list
// then perform sql query
string fullname = "";//from ajax
string email = "";//from ajax
string scheme = "";//from ajax
docalculation(fullname, email , scheme);
}
public bool IsReusable {
get {
return false;
}
}
public void docalculation(string name, string email, string scheme)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["umbracoDbDSN"]);
conn.Open();
SqlCommand cmd1 = conn.CreateCommand();
cmd1.CommandText = "IF NOT EXISTS (SELECT * FROM XXX WHERE email = @XX) INSERT INTO dbo.schemeCustomers(CustomerName, CustomerEmail, schemeType, LoginDate) VALUES (@XX,@XX,@XX,@XX)";
cmd1.Parameters.Add("@XX", SqlDbType.VarChar).Value = email;
cmd1.Parameters.Add("@XX", SqlDbType.VarChar).Value = scheme;
cmd1.Parameters.Add("@XX", SqlDbType.DateTime).Value = DateTime.Now;
int result1 = Convert.ToInt32(cmd1.ExecuteScalar());
conn.Close();
Response.Redirect("/home/schemes.aspx");// response.redirect doesnt works in handler??
}
}
.aspx
$('#logintest').click(function (e) {
e.preventDefault();
var selectedValue = $('#DropDownList2').val();var fullname = $('#name').val();var email = $('#email').val();
var jsonData = '{ "fullname":" + fullname +", "email": " + email +" , "selectedValue" : " + selectedValue +"}';
$.ajax({
url: "/login.ashx",
type: "POST",
data : JSON.stringify({ fullData: jsonData }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d != "") {
alert(response.d);
}
}
});
});
<div id="dialog-form" title="Group Scheme Login">
<form>
<fieldset>
<label for="name">
Full Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
<br />
<label for="email">
Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
<br />
<select id="DropDownList2">
<option value="product1">Camera</option>
<option value="product2">DVD</option>
<option value="product3">AC</option>
</select>
</fieldset>
</form>
<br />
<a href="" id="logintest">Login </a>
</div>
パラメーターをハンドラーに渡す方法について誰でも私を助けることができますか?