通过id来Ajax调用 [英] passing id to ajax call
问题描述
我有这样一个链接<一类=viewp的href =#> @ data.name< / A>
和我想调用一个jQuery AJAX这样
and I would like to call a jquery ajax this way
$(document).ready(function ()
{
$('.viewp').click(function (id)
{
var responseUrl="~/click?id="+id;
$.ajax(
{
type: "GET",
data:id,
url:responseUrl,
success:success
});
});
});
但我不知道如何使用 ID
的 @ data.name
传递到jQuery函数。
如果我替换上面的链接的的href
与 HREF =~/click?id=@data.id
那么应该加载整个页面而不是一些特定区域,并明确AJAX不也行。
But I don't know how the id
of the @data.name
is passed into the jquery function.
If I replace the above link's href
with href="~/click?id=@data.id"
then that is supposed to load the whole page not some specific region and clearly ajax doesn't work also.
[更新]
通过 ID
我的意思是 ID
我的SQL表的主键,我使用WebMatrix中以code我简单的网页。我的数据库表看起来像这样创建表X(ID,姓名)
By id
I would mean the id
primary key of my sql table and I am using webmatrix to code my simple web page. My database table looks like this create table x(id, name)
推荐答案
我还没有得到究竟你的意思
I haven't got what exactly you mean
如果是喜欢
<一类=viewp的href =#ID =someId> @ data.name< / A>
< a class="viewp" href="#" id="someId" >@data.name< /a>
如果你想获得它的ID
if you want to get id of it
然后
$(本).attr(ID);
$(this).attr("id");
如果你想获得文本@ data.name
if you want to get text @data.name
然后
$(本)的.text();
$(this).text();
这篇关于通过id来Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!