这是 jquery ajax 调用 aspnet mvc 控制器的有效数据吗?
我正在将 jquery 与 asp.net mvc 结合使用...我的数据选项是否有效或者我是否缺少某些内容...
$.ajax({
type:"POST",
url: "Materials/GetRecords",
data: "{'currentPage':1,'pageSize':5}",
任何建议...
编辑: 我正在从视图页面调用一个函数,
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
$(document).ready(function() {
getMaterials(0);
});
</script>
我的函数是,
function getMaterials(currentPage) {
$.ajax({
type:"POST",
url: "Materials/GetRecords",
data: "{'currentPage':" + (currentPage + 1) + ",'pageSize':5}",
contentType: "application/json; charset=utf-8",
cache: false,
global: false,
async: false,
dataType: "json",
success: function(data) {
var divs = '';
$("#ResultsDiv").empty();
$.each(data.Results, function() {
divs += '<div class="resultsdiv"><br /><span style="display: inline-block;width:150px;" class="resultName">' + this.Mat_Name + '</span><span class="resultfields" style="padding-left:10px;">Measurement :</span> <span class="resultfieldvalues">' + this.Mes_Name + '</span> <a href="/Materials/Delete/' + this.Id + '">Delete</a> <a href="/Materials/Details/' + this.Id + '">Details</a> <a href="/Materials/Edit/' + this.Id + '">Edit</a></div>';
});
alert("hai");
$("#ResultsDiv").append(divs);
$(".resultsdiv:even").addClass("resultseven");
$(".resultsdiv").hover(function() {
$(this).addClass("resultshover");
}, function() {
$(this).removeClass("resultshover");
});
$("#HfId").val("");
$("#HfId").val(data.Count);
}
});
return false;
}
在视图页面加载上我看到一条警告,内容为 [Object object]
.. 为什么这个...
I am using jquery with asp.net mvc.... Is my data option valid or am i missing some thing...
$.ajax({
type:"POST",
url: "Materials/GetRecords",
data: "{'currentPage':1,'pageSize':5}",
Any suggestion....
EDIT:
I am calling a function from a view page,
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
$(document).ready(function() {
getMaterials(0);
});
</script>
and my function is,
function getMaterials(currentPage) {
$.ajax({
type:"POST",
url: "Materials/GetRecords",
data: "{'currentPage':" + (currentPage + 1) + ",'pageSize':5}",
contentType: "application/json; charset=utf-8",
cache: false,
global: false,
async: false,
dataType: "json",
success: function(data) {
var divs = '';
$("#ResultsDiv").empty();
$.each(data.Results, function() {
divs += '<div class="resultsdiv"><br /><span style="display: inline-block;width:150px;" class="resultName">' + this.Mat_Name + '</span><span class="resultfields" style="padding-left:10px;">Measurement :</span> <span class="resultfieldvalues">' + this.Mes_Name + '</span> <a href="/Materials/Delete/' + this.Id + '">Delete</a> <a href="/Materials/Details/' + this.Id + '">Details</a> <a href="/Materials/Edit/' + this.Id + '">Edit</a></div>';
});
alert("hai");
$("#ResultsDiv").append(divs);
$(".resultsdiv:even").addClass("resultseven");
$(".resultsdiv").hover(function() {
$(this).addClass("resultshover");
}, function() {
$(this).removeClass("resultshover");
});
$("#HfId").val("");
$("#HfId").val(data.Count);
}
});
return false;
}
on the view page load i see an alert saying [Object object]
.. Why this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在,您的数据是一个字符串。您可能希望它是一个对象,如下所示:
您通常会得到一个 JavaScript 对象([Object 对象])。您用它做什么取决于您的应用程序。然而,你是对的,没有警报(除了海),所以我不知道它来自哪里。尝试清除浏览器缓存。
Right now, your data is a string. You probably want it to be an object, like below:
It is normal for you to get a JavaScript object back (the [Object object]). What you do with this depends on your application. However, you're right there's no alert (except the hai), so I don't know where it's coming from. Try clearing your browser cache.
我想你想要:
I think you want: