我在其中一页中,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'
我想使用我的XCordinate
,YCordinate
和ImageName
通过jquery显示图像。但是在警报框内
**[object] [object]**
错误显示。我如何获得和分配该值X和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
数据库值。 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);
}
});
}
注意:尝试在浏览器console
中进行调试,您将了解对象符号的更多详细信息。
查看屏幕快照,您将如何处理
希望这会有所帮助
jQuery ajax发布电子邮件字段 - javascript我不确定为什么我无法发布电子邮件字段的内容,这是我的代码。<html> <head> <title></title> <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> </head>…
jQuery Ajax上传文件php即使没有内容也接收数组 - javascript它正在工作,但是在每次提交时,我什至都收到一个数组,甚至没有将文件添加到文件输入(多文件输入) postData = new FormData(this); $.ajax({ url: "/url", type: "POST", data: postData, cache: false, contentType: fa…
如何用jQuery隐藏模态? - javascript纽扣<button type="button" class="btn" onclick="CountClass()" runat="server" data-toggle="modal" data-target="#inlineForm1…
如何将javascript提示值传递给视图 - javascript有没有一种方法可以将js弹出值直接传递到python / django视图,还是必须使用javascript函数捕获此值然后执行ajax调用?例如:<form> <input type="text" name="name"/> <input type="submit" …
用户刷新页面或导航到其他页面时,侧边栏上的其他广告 - javascript我有一个带有广告部分的侧边栏。当用户导航到其他页面或刷新页面时,我想在该部分上显示其他广告。我想轮播5-10个广告。每个广告都是一个脚本,因此包含10个以上的广告会减慢我的页面速度。在刷新时或用户导航到其他页面时轮播广告的最佳方法是什么?这是给我的wordpress博客的,但我不想使用插件。JS Fiddle<?php $ads = array(…