如果您可以使用简单的html表单,在触发onsubmit时将该值添加到隐藏输入中,并将其发布到将为您重定向的web服务,该方法可能会容易得多。
总之:
你需要与另一个属性来装饰你的btnSaveData方法,改变返回值类型/参数字符串(或适合您需要的任何其他类型):
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public static string btnSaveData(string color)
{
// do sth with the color
return "/SaveSuccess.aspx";
}
而在JS:
// retrieve the color as a string (this is up to you - I don't know what sort of ColorPicker you're using, so this is a placeholder)
function saveColor()
{
var color = $('#myColorPicker').color.toString();
// create the data for the webmethod,
// the parameternames have to be the same as they are on the WebMethod
var colorData = "{ color:'" + color + "'}";
$.ajax({
type: 'POST',
url: "/HomeLoan/ProductConfirmationPop_SaveData.aspx/btnSaveData",
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: colorData,
success: function (response) {
window.location.href = response.d; // redirect on success
},
error: function (response, text, error)
{
alert(response + ' ' + text + ' ' + error);
}
});
希望这有助于工作!