问题描述
我越来越好使用Ajax的方法。我一直运行到小的问题,但。
I'm getting better using the Ajax method. I keep running into small issues though.
例如,我想创建一个显示注释类型的特征,就是当用户点击一个链接,一个模态窗口将与一个伙伴关系code的评论的历史打开。
For instance, I am trying to create a display-comment type feature, where when the user clicks on a link, a modal window will open with a history of the comments for a partner-code.
我已经用PHP将数据返回到网格。我不认为我需要显示code我用来返回数据。
I've already used PHP to return data into a grid. I don't think I need to display the code I used to return the data.
下面是回声我使用到超链接存储数据的属性和其它信息:
Here is the ECHO I'm using to store data-attributes and other information in a HYPERLINK:
<?php
......
echo "<td><a href='' id='pComment' name='".$row[partner_code]."'
class='comment' data-toggle='modal' data-code='".$row[partner_code']."'
data-name='".$row[partner_name]."'>" . $row[partner_name] . "</a></td>";
正如你所看到的,我试图存储在NAME属性的行数据[partner_ code]。我也有一个数据属性被称为数据 - code,它也包含$行[partner_ code]。
As you can see, I tried to store the ROW data [partner_code] in the NAME attribute. I also have a data-attribute called data-code that also contains $row[partner_code].
在我的javascript文件,名为global.js,这里是我到目前为止有:
In my javascript file, called global.js, here is what I have so far:
$('a#pComment').on('click', function()
{
var partnercode = $('a').attr('data-code');
alert(partnercode);
}
我有PHP code,将检索合作伙伴code和运行查询。这工作得很好,但它的JavaScript code上面,我是有问题的。
I have the php code that will retrieve the partnercode and run the query. That works fine, but it's the javascript code above I am having problems with.
目前,当我点击链接,我想提醒伙伴关系code。但我收到的唯一的事情是这样的:
Currently, when I click the link, I am trying to alert the partner-code. But the only thing I am receiving is this:
我尝试这样做:
var partnercode = $('a#pComment').attr('data-code');
不过,警报框将显示0000000001为我点击每一个环节。
But the alert box will show 0000000001 for every single link that I click.
我知道,一旦我能得到窗口至少显示正确的伙伴关系code,然后我就可以送过来给我的PHP文件运行查询,检索的意见。但我不能获得通过这一点。
I know once I can get the window to at least show the correct partner-code, I can then send it over to my php file to run the query to retrieve the comments. But I cannot get passed this.
有没有人看到我的错误?
Does anyone see my error?
请帮忙。
推荐答案
您不能有dupliacte的ID,所以改变一个类:
You cant have dupliacte ids, so change that to a class:
echo "<td><a href='' name='".$row[partner_code]."'
class='comment pComment' data-toggle='modal' data-code='".$row[partner_code']."'
data-name='".$row[partner_name]."'>" . $row[partner_name] . "</a></td>";
然后瞄准在你的js被点击链接与这
$('a.pComment').on('click', function()
{
var partnercode = $(this).attr('data-code');
alert(partnercode);
}
这篇关于PHP AJAX JSON发送到模态窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!