Error on Javascript code querying SharePoint list - javascript

I'm trying to return the contents of a SharePoint list to a HTML page using a JavaScript Query and JSON.
The line:
var query = "**http://collaboration-xxx/sites/it/SystemInventory/_vti_bin/listdata.svc/Knownissues?$select=DeviceID,Title**
does return the DeviceID and Title in browser.
However I don't quite know how I should construct the var query to return results from all the columns. What I've got is:
**var query = " xxx/sites/it/SystemInventory/_vti_bin/listdata.svc/Knownissues?$expand=Knownissues&$filter=DeviceID eq " + window.DeviceId + "";**
I've copied the 'windowsDeviceId' from a previous file which did work. Just having the first var query doesn't return anything and the second returns the attached screen grab. Error code.
The SharePoint columns are: Title, ServiceStatus, Devicetype and DeviceID
JavaScript:
function getDeviceKnownIssues() {
var txtTitle = "";
var txtStatus = "";
//var ServiceStatus = "";
//var Devicetype = "";
//var query = "http://collaboration-xxx/sites/it/SystemInventory/_vti_bin/listdata.svc/Knownissues?$select=DeviceID,Title",
var query = "http://collaboration-xxx.com/sites/it/SystemInventory/_vti_bin/listdata.svc/Knownissues?$expand=Knownissues&$filter=DeviceID eq " + window.DeviceId + "";
var call = $.ajax({
url: query,
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
call.done(function (data,textStatus, jqXHR){
$.each(data.d.results, function(index, item) {
var tempID = result.DeviceId;
var tempTitle = result.Title;
var StatusType = ServiceStatus;
txtTitle = txtTitle + "<p><a href='/sites/it/SystemInventory/SitePages/Service%20Catalogue.aspx?did=" + tempID + "'>" + tempTitle + "</a></p>";
txtStatus = "<p>" + StatusType + "</p>";
});
$('#knowntitle').append($(txtTitle));
$('#servivestatus').append(txtStatus);
});
call.fail(function (jqXHR,textStatus,errorThrown){
alert("Error retrieving data: " + jqXHR.responseText);
});
}
HTML
<html xmlns:mso="urn:schemas-microsoft-com:office:office"
xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
<script src="/jquery-1.10.1.min.js"></script>
<script src="/it/SystemInventory/SiteAssets/scripts/moment.min.js"></script>
<script src="/sites/it/SystemInventory/SiteAssets/getDevices.js"></script>
<script
src="/sites/it/SystemInventory/SiteAssets/getDeviceDetails.js"></script>
<script
src="/sites/it/SystemInventory/SiteAssets/getDeviceKnownIssues.js"></script>
<script type="text/javascript">
function parseQueryString(queryString)
{
var params = {}, queries, temp, i, l;
queries = queryString.split("&");
for ( i = 0, l = queries.length; i < l; i++ ) {
temp = queries[i].split('=');
params[temp[0]] = temp[1];
}
return params;
}
$(document).ready(function(){
function getDeviceID() {
if(typeof parseQueryString === "function") {
if(window.location.href.indexOf("?") >= 0) {
var qs = parseQueryString(window.location.href.split("?")[1])
window.DeviceId = qs.did;
getDeviceDetails();
getDeviceKnownIssues();
}
}
}
getDeviceID();
getDevices();
});
</script>
</head>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border- style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-yw4l{vertical-align:top}
</style>
<table class="tg">
<tr>
<td class="tg-yw4l">
<h1>Devices</h1>
<div id="devices">
</div>
</td>
<td class="tg-yw4l">
<h1>Device Details</h1>
<div id="devicedetails">
</div>
</td>
<td class="tg-yw4l">
<h1>Device Overview</h1>
<div id="deviceoverview">
<div id="devicekind">
</div>
</td>
</tr>
</table>
<table class="tg">
<tr>
<td class="tg-yw4l">
<h1>Accessories</h1>
<div id="deviceacc">
</div>
</td>
<td class="tg-yw4l">
<h1>Typical Usage</h1>
<div id="deviceuse">
</div>
</td>
<td class="tg-yw4l">
<h1>Spare Cell</h1>
<div id=" ">
</div>
</td>
</tr>
</table>
Known Issues
<table class="tg">
<tr>
<td class="tg-yw4l">
<h1>Title</h1>
<div id="knowntitle">
</div>
</td>
<td class="tg-yw4l">
<h1>Service Status</h1>
<div id="servivestatus">
</div>
</td>
<td class="tg-yw4l">
<h1>Device Type</h1>
<div id=" ">
</div>
</td>
</tr>
</table>

Related

Unable to send multiple associative array values from javascript/ajax to php

We are trying to send multiple associative array values from javascript/ajax to php but we receive an empty object/array at the php file.
So can you please help to get values of an associative array from javascript to php?
We have tried serializing array and passing to a php file.
We have tried to convert an array to string and then try to pass it to a php file.
Please check the following code:
// javscript
function saveData(id) {
//var actionData = [];
var actionData = $('#' + id).closest('tr').find("[id^='action_']");
var ownerData = $('#' + id).closest('tr').find("[id^='owner_']");
//var type = $.type(actionData);
//alert(type); exit();
/*alert(actionData[0]['action']);exit;
actionData['owner'] = $('#' + id).closest('tr').find("[id^='owner_']");
actionData[2]['dueDate'] = $('#' + id).closest('tr').find("[id^='dueDate_']");
actionData[3]['completedDate'] = $('#' + id).closest('tr').find("[id^='completedDate_']");
//var myData = JSON.stringify(actionData['owner']);
//alert($('#' + id).closest('tr').find('#projId').val());*/
var dataObject = [];
dataObject['projId'] = $('#' + id).closest('tr').find('#projId').val();
//alert(myData);
//var newData1 = $.extend({}, actionData['owner']);
var newData = $.extend({}, dataObject);
/*dataObject = {
projId: $('#' + id).closest('tr').find('#projId').val(),
riskNumber: $('#' + id).closest('tr').children('td#riskNumber').text().slice(0,-4),
cause: $('#' + id).closest('tr').find('#cause').val(),
effect: $('#' + id).closest('tr').find('#effect').val(),
functionAffectedControl: $('#' + id).closest('tr').find('#functionAffectedControl :selected').val(),
categoryControl: $('#' + id).closest('tr').find('#categoryControl :selected').val(),
impact: $('#' + id).closest('tr').find('#impact :selected').val(),
severityControls: $('#' + id).closest('tr').find('#severityControls').val(),
probability: $('#' + id).closest('tr').find('#probability :selected').val(),
riskOwnerControl: $('#' + id).closest('tr').find('#riskOwnerControl :selected').val(),
manageability: $('#' + id).closest('tr').find('#manageability :selected').val(),
residualProbability: $('#' + id).closest('tr').find('#residualProbability :selected').val(),
residualImpact: $('#' + id).closest('tr').find('#residualImpact :selected').val(),
statusControl: $('#' + id).closest('tr').find('#statusControl :selected').val()
//actions: JSON.stringify(actionArray)
//owners: $('#' + id).closest('tr').find("[id^='owner_']").val(),
//dueDates: $('#' + id).closest('tr').find("[id^='dueDate_']"),
//CompletedDates: $('#' + id).closest('tr').find("[id^='completedDate_']")
}*/
$.ajax({
type: "POST",
url: "/apps/projmgmt/reports/SaveData.php",
data: { data: actionData, owner:ownerData}, //
dataType: 'json',
success: function(response) {
console.log(response);
alert('Data Saved Successfully');
}
});
}
// html
<table class="table table-bordered table-striped tree-basic">
<tbody>
{foreach from=$obj->getRiskActionList() name=risk item=risk}
<tr class="{$class}" data-count="2" id="{$k}">
{$i = $i+1}
{$class='treegrid-'|cat:$i}
{$j = $i-1}
{$classNode='treegrid-parent-'|cat:$j}
<td style="font-weight: bold;">
<div class="treegrid-container">
<span class="treegrid-expander treegrid-expander-collapsed"></span>
{'ACTION'|gettext|escape}</div>
</td>
<td colspan="6" >
<input type="hidden" name="actionId[]" id="actionId_{$k}" value="{$risk->getId()|escape}" />
<div class="treegrid-container">
<span class="treegrid-expander"></span>
<textarea rows="2" cols="100" id="action_{$k}" name="mitigationAction[]" maxlength="256">{$risk->getMitigationAction()|escape}</textarea></div>
</td>
</tr>
<tr class="{$class} {$classNode}">
{$i = $i+1}
{$class='treegrid-'|cat:$i}
<td style="font-weight: bold;" >
<div class="treegrid-container">
<span class="treegrid-expander"></span>{'OWNER_NAME'|gettext|escape}</div></td>
<td>
<input type="text" name="actionOwner[]" size="50" id="owner_{$k}" value="{$risk->getOwnerName()|escape}" maxlength="80"/>
</td>
<td style="font-weight: bold; text-align: center;" >{'DUE_DATE'|gettext|escape}</td>
<td>
<input type="hidden" class="riskPopupCalendar" id="actionDueDate_{$i}" name="actionDueDate[]" value="{$smarty.request.actionDueDate[$i]|escape}">
<div size="10" name="actionDueDateText[]" id="dueDate_{$k}">{if null != {$risk->getDueDate()|escape}}{$risk->getDueDate()->format('d/m/Y')|escape}{/if}</div>
<img src="/images/calendar.gif" id="actionDueDateDatepicker_{$i}" style="width:16px;height:16px;">
<a href="#"><img src="/images/calendar_delete.gif" class="riskPopupCalendarDelete" style="width:16px;height:16px;"
data-input="actionDueDate_{$i}" data-text="actionDueDateText_{$i}" id="actionDueDateDelete_{$i}"></a>
</td>
<td style="font-weight: bold; text-align: center;" >{'COMPLETED_DATE'|gettext|escape}</td>
<td>
<input type="hidden" class="riskPopupCalendar" id="actionCompletedDate_{$i}" name="actionCompletedDate[]" value="{$smarty.request.actionCompletedDate[$i]|escape}">
<div size="10" name="actionCompletedDateText[]" id="completedDate_{$k}>{if null != {$risk->getCompletedDate()|escape}}{$risk->getCompletedDate()->format('d/m/Y')|escape}{/if}</div>
<img src="/images/calendar.gif" id="actionCompletedDateDatepicker_{$i}" style="width:16px;height:16px;">
<a href="#"><img src="/images/calendar_delete.gif" class="riskPopupCalendarDelete" style="width:16px;height:16px;"
data-input="actionCompletedDate_{$i}" data-text="actionCompletedDateText_{$i}" id="actionCompletedDateDelete_{$i}"></a>
</td>
</tr>
<tr class="{$class} {$classNode}">
<div class="treegrid-container">
<span class="treegrid-expander"></span>
<td data-column="name"><img src="/images/blank.gif" class="ib_left"><input type="button" id="{$k|escape}" name="removeActionButton" value="{'REMOVE_ACTION'|gettext|escape}" class="removeActionButton ib"><img src="/images/blank.gif" class="ib_right"></td></div>
</tr>
{$i = $i+1}
{$k = $k+1}
{$class='treegrid-'|cat:$i}
{/foreach}
<tr>
<td></td><td></td><td></td><td></td><td></td>
<td align="right"><img src="/images/blank.gif" class="ib_left"><input type="button" onclick="updateData('{$row}','{$k}');" data-number="{$i}" value="{'ADD_ACTION'|gettext|escape}" class="addActionButton ib"><img src="/images/blank.gif" class="ib_right"></td>
</tr>
</tbody>
</table>
First ensure you data is what you think it is:
var data = JSON.stringify({ data: actionData, owner:ownerData})
console.log(data)
If it is then sent the data object in your ajax call. Then on the the php side I would confirm that the received data matches the sent data. Then parse said data. This should help you narrow down and resolve your issue(s).

Javascript query not returning results from query to SharePoint list

I'm trying to return the contents of a SharePoint list to a HTML page using a JavaScript Query and json.
The two SharePoint columns are called Title and IssueID and are a Single line and Number column. I need it to return it to the Table cell '' in the HTML. I've attached a screen grab from Firefox debugger but I don't know where this is pointing? Debugger
JavaScript:
function getDeviceKnownIssues() {
var txtTitle = "";
var query = "http://collaboration-dev.norgine.com/sites/it/SystemInventory/_vti_bin/listdata.svc/Knownissues?$select=IssueID,Title";
var call = $.ajax({
url: query,
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
});
call.done(function (data,textStatus, jqXHR){
$.each(data.d.results, function(index, item) {
var tempID = result.Id;
var tempTitle = result.Title;
txtTitle = txtTitle + "<p><a href='/sites/it/SystemInventory/SitePages/Service%20Catalogue.aspx?did=" + tempID + "'>" + tempTitle + "</a></p>";
//txtStatus = "<p>" + StatusType + "</p>";
});
$('#knowntitle').append($(txtTitle));
//$('#servivestatus').append(txtStatus);
});
call.fail(function (jqXHR,textStatus,errorThrown){
alert("Error retrieving data: " + jqXHR.responseText);
});
}
HTML
<html xmlns:mso="urn:schemas-microsoft-com:office:office"
xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
<script src="/jquery-1.10.1.min.js"></script>
<script src="/it/SystemInventory/SiteAssets/scripts/moment.min.js"></script>
<script src="/sites/it/SystemInventory/SiteAssets/getDevices.js"></script>
<script
src="/sites/it/SystemInventory/SiteAssets/getDeviceDetails.js"></script>
<script
src="/sites/it/SystemInventory/SiteAssets/getDeviceKnownIssues.js"></script>
<script type="text/javascript">
function parseQueryString(queryString)
{
var params = {}, queries, temp, i, l;
queries = queryString.split("&");
for ( i = 0, l = queries.length; i < l; i++ ) {
temp = queries[i].split('=');
params[temp[0]] = temp[1];
}
return params;
}
$(document).ready(function(){
function getDeviceID() {
if(typeof parseQueryString === "function") {
if(window.location.href.indexOf("?") >= 0) {
var qs = parseQueryString(window.location.href.split("?")[1])
window.DeviceId = qs.did;
getDeviceDetails();
getDeviceKnownIssues();
}
}
}
getDeviceID();
getDevices();
});
</script>
</head>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border- style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-yw4l{vertical-align:top}
</style>
<table class="tg">
<tr>
<td class="tg-yw4l">
<h1>Devices</h1>
<div id="devices">
</div>
</td>
<td class="tg-yw4l">
<h1>Device Details</h1>
<div id="devicedetails">
</div>
</td>
<td class="tg-yw4l">
<h1>Device Overview</h1>
<div id="deviceoverview">
<div id="devicekind">
</div>
</td>
</tr>
</table>
<table class="tg">
<tr>
<td class="tg-yw4l">
<h1>Accessories</h1>
<div id="deviceacc">
</div>
</td>
<td class="tg-yw4l">
<h1>Typical Usage</h1>
<div id="deviceuse">
</div>
</td>
<td class="tg-yw4l">
<h1>Spare Cell</h1>
<div id=" ">
</div>
</td>
</tr>
</table>
Known Issues
<table class="tg">
<tr>
<td class="tg-yw4l">
<h1>Title</h1>
<div id="knowntitle">
</div>
</td>
<td class="tg-yw4l">
<h1>Service Status</h1>
<div id="servivestatus">
</div>
</td>
<td class="tg-yw4l">
<h1>Device Type</h1>
<div id=" ">
</div>
</td>
</tr>
</table>
Replace your call.done method with the below code,
call.done(function (data,textStatus, jqXHR){
var result = data.d.results;
$.each(result , function(index, item) {
var tempID = result.Id;
var tempTitle = result.Title;
txtTitle = txtTitle + "<p><a href='/sites/it/SystemInventory/SitePages/Service%20Catalogue.aspx?did=" + tempID + "'>" + tempTitle + "</a></p>";
//txtStatus = "<p>" + StatusType + "</p>";
});
$('#knowntitle').append($(txtTitle));
//$('#servivestatus').append(txtStatus);
});

I am getting an error on table population from json

I am attempting to populate a table from json data... I am getting an error message on inspect that states the $ is undefined and the resulting table is empty. Any thoughts are appreciated.
Here is the html:
<html manifest="trade.appcache">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="leaflet-0.7.3/leaflet.css" type="text/css" />
<script type="text/javascript" src="leaflet-0.7.3/leaflet.js" rel="javascript" ></script>
<script type="text/javascript" src="js/jquery-1.11.3.min.js" rel="jquery" ></script>
<title>Top Trades</title>
</head>
<body style="margin: 0;padding: 0; display:none;">
<div id="deepbkg"></div>
<div id="fullscreen">
<audio autoplay><source src="audio/trade.wav" type="audio/wav"></audio>
<div id="system" class="mySlides" style="display: block;">
<table id="systems">
<thead>
<tr>
<th class="systems">
<h1>Top System Trades</h1>
</th>
<th>
<div>
<h2>Trade Value</h2>
</div>
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id="logo">
<img src="images/gamestop.png" style="width: 80%;" />
</div>
</div>
<div id="games" class="mySlides" style="display: none;">
<table id="games">
<thead>
<tr>
<th class="systems">
<h1>
Top Game Trades
</h1>
</th>
<th>
<div>
<h2>
PRO
</h2>
</div>
</th>
<th>
<div>
<h3>
Regular Value
</h3>
</div>
</th>
</tr>
</thead>
<tbody>
-->
</tbody>
</table>
</div>
<div id="electronics" class="mySlides" style="display: none;">
<table>
<thead>
<tr>
<th class="systems">
<h1>
Top Electronics Trades
</h1>
</th>
<th>
<div>
<h2>
Trade Value
</h2>
</div>
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id="cube">
<img src="images/cube.gif" style="width: 80%" />
</div>
<script src="js/divslide.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
var genericAJAXRequest = function(jsonFeedURL,paramData,callbackSuccess,callbackFailure,renderFunc) {
var paramData = (paramData !== undefined) ? paramData:{};
$.ajax({
url: jsonFeedURL,
type: 'post',
dataType: 'json',
data: paramData,
})
.done(function(data) {
// On success do this
callbackSuccess(data,renderFunc);
})
.fail(function(e) {
// on failure do these things
console.log("error");
console.log(e);
callbackFailure(e);
});
}
// If we get a good feed do this
var goodFeed = function(data,callback) {
console.log("Loaded Feed!");
console.log(data);
callback(data)
}
var badFeed = function(data) {
console.log("Did not load feed - error!");
console.log(data);
}
var dispSystem = function(data) {
$("#system table h1").text("Top System Trades");
$("#system table h2").text("Trade Value");
console.log(data.TopSystemTrades[0].name);
var row = "";
var loop = 0;
var len = data.TopSystemTrades.length;
var rowClass = "cost";
for (loop = 0; loop < len; loop++) {
row += '<tr><td class="title">'+data.TopSystemTrades[loop].name+'';
row += ' <span>'+data.TopSystemTrades[loop].pf+'</span></td>';
row += '<td class="'+rowClass+'">$'+parseFloat(data.TopSystemTrades[loop].price).toFixed(2).toLocaleString()+'</td></tr>';
}
$("#system table tbody").html(row);
console.log(row);
$("body").fadeIn(1000);
}
var dispGames = function(data) {
var table = $("#games");
$("#games table h1").text("Top Game Trades");
$("#games table h2").text("PRO");
$("#games table h3").text("Regular Value");
var row = "";
var loop = 0;
var len = data.TopGameTrades.length;
for (loop = 0; loop < len; loop++) {
row += '<tr><td class="title">'+data.TopGameTrades[loop].name+'';
row += ' <span>'+data.TopGameTrades[loop].pf+'</span></td>';
row += '<td class="cost">$'+parseFloat(data.TopGameTrades[loop].reg).toFixed(2).toLocaleString()+'</td>';
row += '<td class="cost">$'+parseFloat(data.TopGameTrades[loop].pro).toFixed(2).toLocaleString()+'</td></tr>';
}
$("#games table tbody").html(row);
console.log(row);
$("body").fadeIn();
}
var dispElectronics = function(data) {
var table = $("#electronics");
$("#electronics table h1").text("Top Electronics Trades");
$("#electronics table h2").text("Trade Value");
var row = "";
var loop = 0;
var len = data.TopElectronicsTrades.length;
for (loop = 0; loop < len; loop++) {
row += '<tr><td class="title">'+data.TopElectronicsTrades[loop].name+'';
row += ' <span>'+data.TopElectronicsTrades[loop].pf+'</span></td>';
row += '<td class="cost">$'+parseFloat(data.TopElectronicsTrades[loop].price).toFixed(2).toLocaleString()+'</td></tr>';
}
$("#electronics table tbody").html(row);
console.log(row);
$("body").fadeIn();
}
// Define our urls for the 3 different feeds
var topSystemsFeedURL = "data/top_system_trades_gde.json";
var topGameFeedURL = "data/top_game_trades_gde.json";
var topElectronicsFeedURL = "data/top_electronics_trades_gde.json";
// Make three different calls to load the json data from the urls, and render them to the html
genericAJAXRequest(topSystemsFeedURL, null, goodFeed, badFeed, dispSystem);
genericAJAXRequest(topGameFeedURL, null, goodFeed, badFeed, dispGames);
genericAJAXRequest(topElectronicsFeedURL, null, goodFeed, badFeed, dispElectronics);
});

Beatified HTML code that is derived from database

I would like to Beautify the html code which I get from database.
Which is the best method to do this without using libraries.
I get this information from DB:
#{ var model = (Text.Alert.Models.AlertTemplateModel)Model; var contentItems = model.ContentItems.OrderByDescending(d => d.PublicationDate).ToArray(); } #for (int i = 0; i < contentItems.Count(); i++){ <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr valign="top"> #if (!String.IsNullOrEmpty(contentItems[i].MediaUrl)) { <td width="132"><img src="#(contentItems[i].MediaUrl)" style="display: block;" alt="" width="103"> </td> } <td> <font color="#7391a2" size="2"> <font color="#d1065a" size="3"> #if (!string.IsNullOrEmpty(contentItems[i].Url)) { #(contentItems[i].Title) } else { #(contentItems[i].Title) } </font> <br> #(Raw(contentItems[i].Description)) </font> </td> </tr> </tbody> </table> <br/> }";
This is my function:
function makeReadable(text) {
var readableHTML = text;
var lb = '\r\n';
//var htags = ["var", "#{", "#for", "#if", "#else", "}", "<img", "<html", "</html>", "</head>", "<title", "</title>", "<meta", "<link", "<style", "</style>", "</body>"];
var htags = ["var","#{","#for","#if","#else","}","<img", "<"];
for (i = 0; i < htags.length; ++i) {
var hhh = htags[i];
readableHTML = readableHTML.replace(new RegExp(hhh, 'gi'), lb + hhh);
}
var btags = ["</div>", "</span>", "</form>", "<a", "<font", "</fieldset>", "<br>", "<br />", "</a>", "<hr", "<pre", "</pre>", "<blockquote", "</blockquote>", "<ul", "</ul>", "<ol", "</ol>", "<li", "<dl", "</dl>", "<dt", "</dt>", "<dd", "</dd>", "<\!--", "<table", "</table>", "<caption", "</caption>", "<th", "</th>", "<tr", "</tr>", "<td", "</td>", "<script", "</script>", "<noscript", "</noscript>"];
for (i = 0; i < btags.length; ++i) {
var bbb = btags[i];
readableHTML = readableHTML.replace(new RegExp(bbb, 'gi'), lb + bbb);
}
var ftags = ["<label", "</label>", "<legend", "</legend>", "<object", "</object>", "<embed", "</embed>", "<select", "</select>", "<option", "<option", "<input", "<textarea", "</textarea>"];
for (i = 0; i < ftags.length; ++i) {
var fff = ftags[i];
readableHTML = readableHTML.replace(new RegExp(fff, 'gi'), lb + fff);
}
var xtags = ["<body", "<head", "<div", "<span", "<p", "<form", "<fieldset"];
for (i = 0; i < xtags.length; ++i) {
var xxx = xtags[i];
readableHTML = readableHTML.replace(new RegExp(xxx, 'gi'), lb + lb + xxx);
}
return readableHTML;
}
When I Use my Function the result is this:
#{ var model = (Text.Alert.Models.AlertTemplateModel)Model; var contentItems = model.ContentItems.OrderByDescending(d => d.PublicationDate).ToArray(); } #for (int i = 0; i < contentItems.Count(); i++) {
<table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody>
<tr valign="top"> #if (!String.IsNullOrEmpty(contentItems[i].MediaUrl)) {
<td width="132"><img src="#(contentItems[i].MediaUrl)" style="display: block;" alt="" width="103">
</td> }
<td>
<font color="#7391a2" size="2">
<font color="#d1065a" size="3"> #if (!string.IsNullOrEmpty(contentItems[i].Url)) {
<a href="#(contentItems[i].Url)">#(contentItems[i].Title)
</a> } else { #(contentItems[i].Title) } </font>
<br> #(Raw(contentItems[i].Description)) </font>
</td>
</tr> </tbody>
</table> <br/> }
";

fill radiobutton with data from data base in mvc 4 without using model

code in controller : this action get data from database and fill (classlist) with this data
public ActionResult GetClassListForTeacher()
{
List<string> classlist = null;
ProfileEntities pe= new ProfileEntities();
string uID = HttpContext.Session["NID"].ToString();
int year = 2011;
//int year = DateTime.Now.Year;
int session = set_session();
if (session == 1)//teacher
{
classlist = (from c in pe.CLASSES
join lc in pe.LESSON_CARDS
on new { EDUSTG_CODE = c.EDUSTG_CODE, STATISTICAL_CODE = c.STATISTICAL_CODE, FIRST_YEAR = c.FIRST_YEAR,
GRD_CODE = c.GRD_CODE , OCF_CODE = c.OCF_CODE , CLS_SN = c.CLS_SN}
equals new { EDUSTG_CODE = lc.EDUSTG_CODE, STATISTICAL_CODE = lc.STATISTICAL_CODE_BELONGS_TO, FIRST_YEAR = lc.FIRST_YEAR,
GRD_CODE = lc.GRD_CODE , OCF_CODE = lc.OCF_CODE_BELONGS_TO , CLS_SN = lc.CLS_SN}
where (lc.NID == uID && lc.FIRST_YEAR_HAVE == year)
select c.NAME
).ToList();
}
if (session == 2)//student
{}
return Json(classlist, JsonRequestBehavior.AllowGet);
}
And this code in view
<div class="dialog-fluid" id="MoreOptionModal" style="display: none; height: 300px; overflow: scroll;" title="Options">
<div class="row-fluid">
<div class="block-fluid">
<div class="row-form">
<div class="span12">
<table style="border: 0;">
<tr>
<td style="border: 0;">#Html.RadioButton("type","Friendes",false,new { id = "Friendes"})</td>
<td style="border: 0;"><label>All Friendes</label></td>
</tr>
<tr>
<td style="border: 0;">#Html.RadioButton("type","Teachers",false,new { id = "Teachers"})</td>
<td style="border: 0;"><label>All Teachers As Friends</label></td>
</tr>
<tr>
<td style="border: 0;"></td>
<td style="border: 0;">#Html.RadioButton("type","Same School",false,new { id = "Same_School" })</td>
<td style="border: 0;"><label>Same School</label></td>
</tr>
<tr>
<td style="border: 0;"></td>
<td style="border: 0;">#Html.RadioButton("type","Other School",false,new { id = "Other_Schools"})</td>
<td style="border: 0;"><label>Other School</label></td>
</tr>
<tr>
<td style="border: 0;">#Html.RadioButton("type","Schoolmates",false,new { id = "Schoolmates"})</td>
<td style="border: 0;"><label>All Students As Friends</label></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
i want add list of radio buttons after last radio button which called (Schoolmates)
and this is the code in js
$("#MoreOptionModal").dialog({
autoOpen: false,
modal: true,
});
$("#options").live("click", function () {
debugger;
$("#MoreOptionModal").dialog('open');
$.ajax({
url: "/Mail/GetClassListForTeacher",
type: "POST",
datatype: "json",
data: { },
traditional: true,
success: function (result) {
}
});
});
the problem is i already have model in my view and i retrieve data from database and i want to show it my view
Add this code to success function, of course you have to adapt the solution to your needs, but basically this is the workaround.
$.each(result, function(i, name){
var trToAppend="
<tr>
<td style="border: 0;"><input type='radio' name='type' id='" + name + "'/></td>
<td style="border: 0;"><label>" + name + "</label></td>
</tr>
";
$('table').append(trToAppend);
});
code in js
$("#options").live("click", function () {
debugger;
$("#MoreOptionModal").dialog('open');
$.ajax({
url: "/Mail/GetClassListForTeacher",
type: "POST",
datatype: "json",
data: { },
traditional: true,
success: function (result) {
$("#ForTest").val(result);
var d = $("#ForTest").val().split(",");
for (var i = 0; i < d.length; i++) {
//alert(d[i])
var trToAppend="<tr><td><input type='radio' name='type' id='" + d[i] + "'/></td><td><label>" + d[i] + "</label></td></tr>";
$("#MyTest").append(trToAppend);
}
}
});
});
and i add this line in view
<input id="ForTest" type="hidden" />
i take the list then i split it then i append the html

Categories

Resources