从webmethod获取值并在webform文本框中显示
我是一名嵌入式软件开发人员(适用于微控制器),具有有限的Web开发经验。
我正在编写一个带有webform的简单web服务来获取web方法收到的数据并将其显示在Web表单上(作为技术演示的一部分)。
见下文 - 我非常怀疑建议的解决方案是否有效,但它是显示我想要做的最简单的方法。
Hi,
I am an embedded software developer (for microcontrollers) with limited web development experience.
I am writing a simple webservice with a webform to take data received by a webmethod and display it on a web form (as part of a tech demo).
See below - I highly doubt the proposed solution is valid, but it is the easiest way of showing what I am trying to do.
[WebMethod]
public string UploadData(string Password, string Serial, string ConnectionReason, string ResetReason)
{
txtPassword.Text = Password;
txtSerial.Text = Serial;
return txtResponse.text
}
同样,我希望HTTP响应webmethod将一些文本框的值返回给客户端。
什么是最直接的方式实现这个?
Similarly, I would like the HTTP response to the webmethod to return the value of some textboxes back to the Client.
What is the most straightforward way of implementing this?
只需使用jQuery Ajax即可轻松实现: -
让我们说下面是我作为asmx的网络方法
Simply you can accomplish this using jQuery Ajax very easily :-
Let say below is the web method i am having as asmx
[WebMethod(EnableSession = true)]
public string GetData(int id, string name)
{
string jsonData = string.Empty;
// var data = get data from database here;
jsonData = Parser.EntityToJSon(data);
return jsonData;
}
下面是一个jQuery ajax代码,用于调用此Web方法获取数据的ajax: -
Here below one is the jQuery ajax code for the ajax call to this web method for fetching data :-
( function (){
.ajax({
type: POST ,
url: ../ WebMethods / WebService.asmx / GetData,
data: {Id: + {pass ID here} + ,名称:' + {传递名称值} + '},
contentType: application / json; charset = utf-8,
dataType: json,
成功: function (响应){
var result =
.ajax({ type: "POST", url: "../WebMethods/WebService.asmx/GetData", data: "{Id:" + {pass ID here} + ",Name:'" + {pass name value here} + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { var result =