gpt4 book ai didi

javascript - Jquery C# 中的数据集值

转载 作者:行者123 更新时间:2023-11-28 03:09:47 24 4
gpt4 key购买 nike

我有一个页面,其中 URL 包含查询字符串值。

QSecID=164&QTempId=55&QSecName=New%20Temp%20Bt

当页面加载它们并尝试获取值时,它工作正常。

$(document).ready(function() {

function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
var urlName = getUrlParameter('QSecName');
alert(urlName);
getImageData(urlName); //Pass Query String Value to Function
});

现在我将此值传递给 C#、ASPX.CS 页面,并尝试根据 QSecName 获取数据。但我有错误。这是我的 Jquery 函数。

function getImageData(name) {

// alert(nextDay);
$.ajax({

type: "POST",

url: "Section.aspx/GetImageData",

//data: '',
data: JSON.stringify({
"dataSecName": name
}),

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(data) {
alert("Success");
alert(JSON.parse(data.d));

}

});
}

我的 C# 页面返回 Jquery 中的数据集。

[WebMethod()]
public static string GetImageData(string dataSecName)
//public static string GetRole()
{
clsSection objSectNew = new clsSection();
DataSet DS = new DataSet();
DS = objSectNew.GetImageDataByJQ(dataSecName);
return JsonConvert.SerializeObject(DS);
}

编辑代码 1这是我的 SQL 语句,当我运行页面时执行该语句,

DS = objSectNew.GetImageDataByJQ(dataSecName);

此方法传递查询字符串值以执行存储过程。

select mhp.ImageName,mhp.HotSpotID,imgdetail.XCordinate,imgdetail.YCordinate
from tbl_SOAPDetailsInfo e inner join M_ImageHotSpot mhp on e.ImgHotSpotName=mhp.ImgHotSpotNameByUser
inner join M_ImageHotSpotDetail imgdetail on mhp.HotSpotID=imgdetail.HotspotIDFK where e.SOAP_D_Name='New Temp Bt'

我想使用我的XColuteYColuteImageName来使用jquery显示图像。但在警报框内

**[object] [object]**

错误显示。我怎样才能获取并分配这个值X AND Y值并显示在DIV中。
编辑代码2

ImageName               XCordinate  YCordinate
$parent in angularjs.png 1146 590
$parent in angularjs.png 1216 588
$parent in angularjs.png 1188 626
$parent in angularjs.png 1162 582
$parent in angularjs.png 1193 586

数据库值(value)。 JSON 格式数据

{"d":"{\"Table\":[{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1146\",\"YCordinate\":\"590\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1216\",\"YCordinate\":\"588\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1188\",\"YCordinate\":\"626\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1162\",\"YCordinate\":\"582\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1193\",\"YCordinate\":\"586\"}]}"}

最佳答案

因此,根据您的问题 [object] [object] 不是错误。这意味着您无法以正确的方式获取它。

虽然我不确定您从 data 中的后端代码发送什么样的数据,但您可以尝试以下方式,

     var data = "{\"Table\":[{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1146\",\"YCordinate\":\"590\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1216\",\"YCordinate\":\"588\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1188\",\"YCordinate\":\"626\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1162\",\"YCordinate\":\"582\"},{\"ImageName\":\"$parent in angularjs.png\",\"ImagePath\":\"~/Administration/imageHotspot/$parent in angularjs.png\",\"HotSpotID\":11,\"XCordinate\":\"1193\",\"YCordinate\":\"586\"}]}"

var obj = JSON.parse(data);

console.log(obj.Table);
var tableObj = obj.Table

console.log(obj.Table);

var arrayLength = tableObj.length;

for (var i = 0; i < arrayLength; i++) {
console.log(tableObj[i].ImageName);
console.log(tableObj[i].XCordinate);
console.log(tableObj[i].YCordinate);
alert(tableObj[i].YCordinate);
}

现在,如果您用上面的示例替换代码,您的代码应如下所示:

 function getImageData(name) {
// alert(nextDay);
$.ajax({
type: "POST",
url: "Section.aspx/GetImageData",
data: JSON.stringify({
"dataSecName": name
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var obj = JSON.parse(data);

console.log(obj.Table);
var tableObj = obj.Table

console.log(obj.Table);

var arrayLength = tableObj.length;

for (var i = 0; i < arrayLength; i++) {
console.log(tableObj[i].ImageName);
console.log(tableObj[i].XCordinate);
console.log(tableObj[i].YCordinate);
alert(tableObj[i].YCordinate);
}

});
}

Note : Try to debug in browser console you would understand object notation more details.

查看屏幕截图,您将如何做到这一点

enter image description here

希望这会有所帮助

关于javascript - Jquery C# 中的数据集值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60238200/

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