如何在MVC中使用j query ajax访问服务的数据? [英] How can accesses the data for the services using j query ajax in MVC ?
本文介绍了如何在MVC中使用j query ajax访问服务的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在mvc中调用j查询ajax的帖子中调用服务时?为了检查传递一些id,值是否在控制器中,但是在断点处显示该值为Null?给我一些正确的指南 到我的代码。
我尝试过:
控制器代码:---
When i am calling the services in the post of j query ajax in mvc ?For that i am Checking to passing some id,value is coming in controller or not,But showing that value is Null in Break point ? Gave me some proper guides to my code .
What I have tried:
Code of controller:---
[HttpPost]
public JsonResult Filters(string id)
{
var sd= id;
return Json(sd, JsonRequestBehavior.AllowGet);
}
代码:---
Code of View:---
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function ()
{
$('#rating-5').click(function ()
{
alert($('#rating-5').attr("value"));
var fe = $('#rating-5').val("5");
alert(fe);
$.ajax
({
url: '/Home/Filters',
// url:'/Home/Rating',
//contentType: 'application/json; charset=utf-8',
type: 'POST',
data: { sdsd: $('#rating-5').attr("value") },
dataType: 'json',
success: function (result) {
alert(result);
console.log(result);
},
error: function (status)
{
alert(status);
}
});
});
});
</script>
<pre><body>
<div class="widget-sidebar start-rating-sidebar">
<h4 class="title-sidebar">Star rating</h4>
<ul class="widget-rate">
<li>
<div class="radio-checkbox">
<input id="rating-5" type="checkbox" class="checkbox">
<label for="rating-5"></label>
</div>
<div class="group-star">
</div>5 Stars <span>12</span>
</li>
<li>
<div class="radio-checkbox">
<input id="rating-4" type="checkbox" class="checkbox">
<label for="rating-4"></label>
</div>
<div class="group-star">
</div>4 Stars <span>12</span></li>
<li>
<div class="radio-checkbox">
<input id="rating-3" type="checkbox" class="checkbox">
<label for="rating-3"></label>
</div>
<div class="group-star">
</div>3 Stars <span>12</span>
</li>
<li>
<div class="radio-checkbox">
<input id="rating-2" type="checkbox" class="checkbox">
<label for="rating-2"></label>
</div>
<div class="group-star">
</div>2 Stars <span>12</span>
</li>
<li>
<div class="radio-checkbox">
<input id="rating-1" type="checkbox" class="checkbox">
<label for="rating-1"></label>
</div>
<div class="group-star">
</div>1 Stars <span>12</span>
</li>
<li>
<div class="radio-checkbox">
<input id="rating-6" type="checkbox" class="checkbox">
<label for="rating-6"></label>
</div>
<div class="group-star">
</div>Not Rated <span>12</span>
</li>
</ul>
</div>
</body>
问题是: - 当复选框点击时,值5显示在更改框中。但是控制器值显示为什么?
Issues is:-when checkbox click is value 5 is displaying in alter box.But in controller value showing null what ?
推荐答案
(文件).ready(function()
{
(document).ready(function () {
(' #rating-5')。click(function()
{
alert(
('#rating-5').click(function () { alert(
('#rating-5')。attr(value)) ;
var fe =
('#rating-5').attr("value")); var fe =
这篇关于如何在MVC中使用j query ajax访问服务的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文