我的ASP.NET页面上有一个jQuery UI对话框:
$(function () {
var dialog,
fascicolo = getQuerystring("fascicolo"),
annotazione = $("#nota").val();
function addUser() {
var nota = {};
nota.fascicolo = fascicolo;
nota.notastr = annotazione;
$.ajax({
...
}
});
dialog.dialog("close");
}
dialog = $("#dialog-form").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Inserisci la nota": addUser,
Cancel: function () {
dialog.dialog("close");
}
},
close: function () {
}
});
$("#create-user").button().on("click", function () {
event.preventDefault();
dialog.dialog("open");
});
});
</script>
这是我的div:
<div id="dialog-form" title="Create new nota">
<fieldset>
<label for="nota">Nota</label>
<input type="text" name="nota" id="nota" value=""/>
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px"/>
</fieldset>
</div>
这就是问题,用json调用的web方法得到 $(&#34;#nota&#34;)。val()为空!帮帮我...我试过了
.parent().appendTo(jQuery("form:first"));
open: function (type, data) {$(this).parent().appendTo(jQuery("form:first"))},
解决方案,但没有......
修改
这是ajax调用
function addUser() {
var nota = {};
nota.fascicolo = fascicolo;
nota.notastr = annotazione;
$.ajax({
type: "POST",
url: "dettagliofascicolo2.aspx/SaveNota",
data: '{nota: ' + JSON.stringify(nota) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("Nota inserita correttamente!");
window.location.reload();
}
});
dialog.dialog("close");
}
这是由ajax调用的webmethot:
<WebMethod()> _
<ScriptMethod()> _
Public Shared Sub SaveNota(nota As nota)
Dim conString As String = ConfigurationManager.ConnectionStrings("connMySql").ConnectionString
Dim myConnection As MySqlConnection = New MySqlConnection(conString)
Dim stringa_ins As String = "INSERT INTO `note_fascicolo`(`fascicolo`, `note`) VALUES (@fascicolo,@nota)"
Dim dbcomm As New MySqlCommand(stringa_ins, myConnection)
dbcomm.Parameters.Add("@fascicolo", MySqlDbType.Int32)
dbcomm.Parameters.Add("@nota", MySqlDbType.VarChar)
dbcomm.Parameters("@fascicolo").Value = nota.fascicolo
dbcomm.Parameters("@nota").Value = nota.notastr
Dim ident As Integer
Try
myConnection.Open()
ident = dbcomm.ExecuteScalar()
Catch ex As Exception
'Response.Write(ex.Message)
'Response.End()
End Try
myConnection.Close()
End Sub
Public Class nota
Public Property fascicolo() As String
Get
Return _fascicolo
End Get
Set(value As String)
_fascicolo = value
End Set
End Property
Private _fascicolo As String
Public Property notastr() As String
Get
Return _notastr
End Get
Set(value As String)
_notastr = value
End Set
End Property
Private _notastr As String
End Class