gpt4 book ai didi

Javascript 设置表单属性

转载 作者:行者123 更新时间:2023-11-28 00:12:48 25 4
gpt4 key购买 nike

Javascript code:

<script type="text/javascript">
function submitForm() {
alert("hhhhh");

// document.forms[0].action ="http://navislink.apmtmumbai.com/express/lines/cnt_details.jsp";
// document.forms[0].submit();
$.ajax({
type: "POST",
url: "index.aspx/GetCurrentTime",
data: '{name: " + rashmi + " }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (data, status) {

console.log("CallWM");
alert(data.d);
},
failure: function (data) {
alert(data.d);
},
error: function (data) {
alert(data.d);
}
});

}

function OnSuccess(response) {
alert(response)
document.forms[0].action =response; //"http://navislink.apmtmumbai.com/express/lines/cnt_details.jsp";
document.forms[0].submit();
}

网络方法

 [System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
//return "Hello " + name + Environment.NewLine + "The Current Time is: "
//+ DateTime.Now.ToString();
DataTable dtContTrack = new DataTable();
dtContTrack = Class1.GetRecord1("SELECT u_url FROM urltb WHERE u_id=( SELECT max(u_id) FROM urltb )");
return dtContTrack.Rows[0]["u_url"].ToString();
}

这是我的简短代码,我想设置一些到表单操作的链接。按钮单击submitForm()正在执行,如果硬编码代码它将起作用;如果我在onsuccess方法中使用,则不会设置url。请帮我解决。

最佳答案

响应始终是对象。为了获取您的数据,您必须使用response.d。

来源:- http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/

“.d” what? If you aren’t familiar with the “.d” I’m referring to, it is simply a security feature that Microsoft added in ASP.NET 3.5’s version of ASP.NET AJAX. By encapsulating the JSON response within a parent object, the framework helps protect against a particularly nasty XSS vulnerability.

您需要编写response.d,如下所示:-

function OnSuccess(response) {
alert(response.d)
document.forms[0].action =response.d; //"http://navislink.apmtmumbai.com/express/lines/cnt_details.jsp";
document.forms[0].submit();
}

关于Javascript 设置表单属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30747625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com