我正在尝试使用从JSON设置的id和value属性创建输入。我有一个获取JSON的ajax调用,返回的数据很好,对于JSON中的每个对象,我想创建一个带有ID和JSON值的按钮。
Ajax电话:
$.ajax({
type: "GET",
url: '@Url.Action("GetSubjects", "CommAPI")',
dataType: "json",
success: function (data) {
$.each(data, function (index, element) {
$('#subjects').append('<input type ="button" id=" ' + element.Id + ' " value=' + element.Title + ' class=k-button />');
});
},
});
然而,JSON中的对象还有5个附加属性,而不仅仅是Id和Title。将调试器放置在创建输入的行时,Id和Title未定义。
如何从此JSON创建这些输入?
从控制台复制的返回JSON:
14:41:57.928 {"Data":[{"Id":1,"IdCSite":1,"IdDEvent":1,"Title":"Test","CaseName":null,"Description":"dsadasdasda","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false},{"Id":2,"IdCSite":1,"IdDEvent":1,"Title":"Test2","CaseName":null,"Description":"sdadasdas","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false},{"Id":3,"IdCSite":1,"IdDEvent":1,"Title":"test 3","CaseName":null,"Description":"sdadasdasda","InsertedDate":"/Date(-62135596800000)/","SelectedUsers":null,"ViewSelectedUsers":null,"IsCurrentUserIncluded":false}],"Total":3,"AggregateResults":null,"Errors":null}1 messageboard:128:25
答案 0 :(得分:5)
根据您的JSON,您需要使用Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id', 'name', 'email', 'website', `comment`, `timestamp`, `articleid`) VALUE' at line 1
对象的<?
if( $_POST )
{
$con = mysql_connect("localhost","iluxcoke_myuser","qwert2012");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("iluxcoke_inmoti6_mysite", $con);
$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_website = $_POST['website'];
$users_comment = $_POST['comment'];
$users_name = mysql_real_escape_string($users_name);
$users_email = mysql_real_escape_string($users_email);
$users_website = mysql_real_escape_string($users_website);
$users_comment = mysql_real_escape_string($users_comment);
$sql = "SELECT * FROM `comments` LIMIT 0, 30 ";
$sql= "INSERT INTO `comments`('id', 'name', 'email', 'website',
`comment`, `timestamp`, `articleid`) VALUES ( id, '$users_name',
'$users_email', '$users_website', '$users_comment',
'CURRENT_TIMESTAMP ');";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
//mysql_query($sql)
echo "<h2>Thank you for your Comment!</h2>";
mysql_close($con);
}
?>
属性。因此将Data
更改为data
$.each(data,
答案 1 :(得分:0)
您可以直接使用jQuery属性来实现:
A1 =[1 0 0 1 1 0 0 0 0 0 0 0 0 0;...
1 1 0 0 0 1 0 0 0 0 0 0 0 0;...
1 1 1 0 0 0 1 0 0 0 0 0 0 0;...
0 1 1 1 0 0 0 1 0 0 0 0 0 0;...
0 0 1 1 0 0 0 0 1 0 0 0 0 0;...
1 1 0 1 1 0 0 1 0 1 0 0 0 0;...
1 0 1 1 0 1 0 0 1 0 1 0 0 0;...
1 1 1 0 0 0 1 1 1 0 0 1 0 0;...
0 1 1 1 1 1 1 0 0 0 0 0 1 0;...
0 0 0 0 1 1 1 1 1 0 0 0 0 1;...
0 1 1 1 1 0 1 1 1 0 1 1 1 0;...
0 0 0 1 0 0 0 1 0 0 0 0 0 0;...
0 0 1 0 0 0 0 1 0 0 0 0 0 0;...
1 1 1 1 0 0 0 0 0 0 0 0 0 0;...
0 0 1 1 0 0 0 0 1 1 0 0 0 0;...
0 0 1 0 0 0 0 0 0 0 0 0 0 1 ];
D1=[0; 0; 0; 0 ; 0; 0 ; 0; 0 ; 0 ; 0 ; 103 ; 198 ; 105 ; 115; 175 ; 14];
for ii=1:14
% Find ii-th pivot index between row ii and last row
PivIndex=find(A1(ii:end,ii),1)+ii-1;
% Switch ii-th row with Pivot row
A1([ii PivIndex],:)=A1([PivIndex ii],:);
D1([ii PivIndex])=D1([PivIndex ii]);
% Find all rows other than row ii containing a 1 in column ii
RowIndexes=find(A1(:,ii));
RowIndexes(RowIndexes==ii)==[];
% Add row ii to all rows in RowIndexes, do the same in D
A1(RowIndexes,:)=mod(A1(RowIndexes,:)+repmat(A1(ii,:),numel(RowIndexes),1),2);
%% Problem with my answer was here, as the sum in GF(256) doesn t work like that. (GF(256),+) behaves like ((Z/2Z)^8,+)... See prequisite for summing in GF(256)
% D1(RowIndexes)=mod(D1(RowIndexes)+repmat(D1(ii),numel(RowIndexes),1),256);
D1(RowIndexes)=SumInGF256(D1(RowIndexes),repmat(D1(ii),numel(RowIndexes),1));
end
% Now A1 is diagonal, with both last rows being zero. Problem is D
% has to be 0 aswell on the 2 last positions to get 0=0..
% Check if D(15:16)==[0;0] if not the system has no solution
if isequal(D1(15:16),[0;0])
A2=A1(1:14,:);
C=D1(1:14)
else
disp('No solution')
end
如何命名您的变量,例如&#39; Id&#39;是Javascript的关键词。如果它是一个用户,你应该像idu一样命名。
享受:)