【发布时间】:2021-04-28 02:03:23
【问题描述】:
我有一个运行 SQL 语句的 AJAX Web 服务,它可以工作。
我正在尝试从我的网页中获取一个 HTML 值并将其用作我的查询中的附加变量。
这是我在网页上捕获该变量的方式。
<div style="margin-left:0px">
<label>Enter Number here: </label><br>
<input type= text id="demo">
</div>
...这是我的 Web 服务调用。
//Generate code
function Generate() {
var myGrid = $('#jqquotes'),
selectedRowId = myGrid.jqGrid('getGridParam', 'selrow');
docid = myGrid.jqGrid('getCell', selectedRowId, 'docid');
document.getElementById("demo").innerHTML = document.getElementById("demo").value;
alert(document.getElementById("demo").value);
var quotenum = document.getElementById("demo".value);
if (confirm('Are you sure you want to generate a quote?')) {
$.ajax({
url: '/WebService1.asmx/Generate',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "GET",
data: { docid: docid, quotenum: JSON.stringify(quotenum) },
success: function () {
//Get selected
var grid = $("#jqquotes");
var rowKey = grid.jqGrid('getGridParam', "selrow");
//Refresh grid
$('#jqquotes').trigger('reloadGrid');
//Set Selected
setTimeout(function () {
jQuery('#jqquotes').jqGrid('setSelection', rowKey);
}, 200);
}
});
} else {
return false
}
}
警告框正确显示来自框 id“Demo”的 HTML 值
但是 WebService 失败,说值为 NULL,JSON 响应是: 消息“参数化查询 '(@docid nvarchar(5),@quotenum nvarchar(4000))UPDATE [dbo].[quote' 需要参数 '@quotenum',但未提供。”
...GET URL 将值显示为 NULL
https://localhost:44338/WebService1.asmx/Generate?docid=10146"enum=null
非常感谢任何帮助。
【问题讨论】:
标签: javascript asp.net ajax web-services