Convert Json parsed date to fit html5 input date

I am using Knockout to make a nice looking Gui like so

Javascript:

   viewModel = {
        lookupCollection: ko.observableArray()
    };

    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url:  "@Url.Action("GetView", "FakturaOmfangs", new {area = "" , id = ViewBag.id})",
        }).done(function (data) {
            $(data).each(function (index, element) {
                var mappedItem =
                    {
                        FakturaId: ko.observable(element.FakturaId),
                        FakturaProdukterId: ko.observable(element.FakturaProdukterId),
                        Beskrivelse: ko.observable(element.Beskrivelse),
                        Periode: ko.observable(element.Periode),
                        EndDate: ko.observable(element.EndDate),
                        procent: ko.observable(element.procent),
                        Rabat: ko.observable(element.Rabat),
                        Pris: ko.observable(element.Pris),
                        Ialt: ko.observable(element.Ialt),
                        Value: ko.observable(element.Value),
                        Mode: ko.observable("display")
                    };
                console.log(mappedItem);
                viewModel.lookupCollection.push(mappedItem);
            });
            ko.applyBindings(viewModel);
        });
    });

the EndDate is a Datetime? parsed from controller like this

  return Json(list, JsonRequestBehavior.AllowGet);

This is my input where i would like to put the Date into, so i can edit it.

<td><input class="form-control" type="date" data-bind="value: EndDate" /></td>

How do i format the date to the correct format? so that i can use it in input type=Date ?

Thanks.
Benny.


Source: stackoverflow-javascript

Translating PHP http request into C# .NET

I have written this code in PHP to make a HTTP request to my server to retrieve my data:

<?php


$client_secret= '';
$data= array(

'email' => '**********',

'password' => '******',

'client_id' => '*******'
);

$api_url='******';

$json_data=json_encode($data);

$signature_string = md5($json_data . $client_secret); 


$post_data = 'signature='.$signature_string.'&data='.urlencode($json_data);

$curl = curl_init($api_url); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_POST, 1); 

curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);

$result = curl_exec($curl); 

print_r($result);


curl_close($curl); 

?> 

And this works good. Data is returned in JSON format. Now I’m trying to do exactly the same thing but in .NET

I have managed to recreate in .NET C# exactly the same postData parameter as in PHP, but I’m not sure how to pass it in C# with the request itself… So I’ve decided to use .NET’s restsharp library to make the request like this:

  public void GetResponse()
        {
            string client_secret = "*****";

            var serializer = new JavaScriptSerializer();
            string json_data = serializer.Serialize(new { email = "*****", password = "*****", client_id = "*****" });

            var signature_string = CalculateMD5Hash(json_data + client_secret).ToLower();

            var postData = "signature=" + signature_string + "&data=" + Server.UrlEncode(json_data);
            var client = new RestClient("mysite.com");
            var request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddHeader("cache-control", "no-cache");
            request.AddParameter("application/x-www-form-urlencoded", "signature="+signature_string, ParameterType.RequestBody);
            request.AddParameter("application/x-www-form-urlencoded", "data=" +json_data, ParameterType.RequestBody);

            IRestResponse response = client.Execute(request);

        }

Please note in C# and in PHP variables:

$post_data 

and 

var postdata

are exactly identical. Now I just don’t know how to pass them alongside the request because the server always responds me that request data was empty..

What am I doing wrong here?


Source: stackoverflow-php

Click event on dynamic button in table

I have a datatables element on my page with a hidden first column, and an empty column at the end to contain a button.

I’m trying to get the click event of that button to:

  1. Hide the button,
  2. Show a ‘loading’ icon – fontawesome icon already in the column
  3. Retrieve the value of the hidden columns corresponding row
  4. Show a success/fail icon – to be added but will be a fontawesome icon

CSHTML:

@foreach (var item in Model.Items) {
DATA_ID KPI Name Value 1 Value 2 Value 3 Date For Value Type Added By Added On Action
@item.DATAID @item.KPIHead @item.Value1 @item.Value2 @item.Value3 @item.FromDate.ToString("dd/MM/yyyy") @item.Type @item.AddedBy @item.AddedOn.ToString("dd/MM/yyyy")
</td> </tr> } </tbody> </table> </div> </div>

Script:

$(document).ready(function () {
    var table = $('#SignOffTable').DataTable({
        paging: true,
        searching: false,
        ordering: false,
        pagingType: "simple_numbers",
        lengthChange: false,
        bfilter: true,
        info: true,
        "columnDefs": [
        { "visible": false, "targets": 0 }
        ]
    });
});

$("#SignOffTable button").click(function () {
    var trElem = $(this).closest("tr");
    var firstTd = $(trElem).children("td")[0];
    alert($(firstTd).text())
})

However I can't seem to access the hidden column's data, or successfully hide the button/show the loading spinner.


Source: stackoverflow-javascript