我正在尝试进行ajax调用,它通过JQUERY传递4个参数。它没有发生,也没有给任何error. onsuccess
输出值。我想填写2个文本框值,如下所示。
ClientSide:
function doCalculation(){
var obj = {};
obj.apple = $("#ddlapple :selected").text();
obj.banana = $("#ddlbanana :selected").text();
obj.chocolate = parseFloat($("#txtchocolate").val().toString()).toFixed(2);
obj.doll = parseFloat($("#txtdoll").val().toString()).toFixed(2);
if (obj.chocolate > 0 && obj.doll > 0) {
$.ajax({
type: "POST",
url: "xxxxxxxxxxxxxxx.aspx/Calculation",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
}
成功后,我想用输出参数填充两个文本框值,如下所示
function OnSuccess(response) {
var outputparams = response.d;
$("#txtbox1").val(outputparams.abc);
$("#txtbox2").val(outputparams.xyz)
}
VB.NET代码:
_ 公共共享函数计算(ByVal apple As String,ByVal banana As String,ByVal chocolate As Decimal,ByVal doll As Decimal)As ClassParams
{
//这里有一些计算
}
Public Class ClassParams
Public Property abc() As Decimal
Public Property xyz() As Decimal
结束班
提前致谢:)
答案 0 :(得分:0)
没有选择'失败'在jquery ajax中。用“错误”替换失败'并检查。
答案 1 :(得分:0)
将来为其他人发布答案。我用过很多方法,但只有这个方法适合我。
function doCalculation() {
var obj = {};
obj.apple = $("#ddlapple :selected").text();
obj.banana = $("#ddlbanana :selected").text();
obj.chocolate = parseFloat($("#txtchocolate").val().toString()).toFixed(2);
obj.doll = parseFloat($("#txtdoll").val().toString()).toFixed(2);
if (obj.chocolate > 0 && obj.doll > 0) {
$.ajax({
type: "POST",
url: "xxxxxxxxxxxxxxx.aspx/Calculation",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
data: '{"apple":"' + obj.apple + '","banana":"' + obj.banana + '","chocolate ":"' + obj.chocolate + '","doll":"' + obj.doll + '"}',
success: OnSuccess,
error: function (response) {
alert(response.d);
}
});
}
}
function OnSuccess(response) {
var outputparams = response.d;
$("#txtbox1").val(outputparams.abc);
$("#txtbox2").val(outputparams.xyz)
}
VB.NET代码:
将输出参数作为类对象返回,并在Jquery的客户端使用它来填充具有该值的文本框
<System.Web.Services.WebMethod()> _
Public Shared Function Calculation(ByVal apple As String, ByVal banana As String, ByVal chocolate As Decimal, ByVal doll As Decimal) As ClassParams
{
// some calculation here
}
Public Class ClassParams
Public Property abc() As Decimal
Public Property xyz() As Decimal
End Class