Uncaught TypeError: Cannot read property ‘fromJSON’ of undefined

I am trying to display menu data after the ajax call returns from the following page:

<head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">

    https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js
    https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js
    <!-- https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js
    https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.js -->
</head>


<body>

    <h1>page loaded</h1>

    
</body> function OrderPageViewModel() { var self = this; // self.menu_loaded_success_callback = function(data) { // var retrieved_menu = data["menu"]; // self.menu = ko.observable(retrieved_menu); // console.log(retrieved_menu) // alert(data); // } // // self.get_data(menu_url).done(self.menu_loaded_success_callback); } var menu_url = "menu/get-menu"; get_menu_data = function(url_ending){ console.log("running get_data"); var URL = "/api/&/".replace("&", url_ending); console.log("URL: ", URL); return $.ajax({ dataType: "json", url: URL, // type: "GET", }); } get_menu_data(menu_url).done(function(data){ var vm = new OrderPageViewModel(); console.log(data); vm = ko.mapping.fromJSON(data); ko.applyBindings(vm); }).fail(function(){ alert("failed"); }); // ko.applyBindings(new OrderPageViewModel());

enter image description here

I followed the example at wait for ajax result to bind knockout model and it is saying Uncaught TypeError: Cannot read property 'fromJSON' of undefined

Any help appreciated


Source: stackoverflow-javascript

javascript googlemaps missing lat and long

I have a script that auto fills form in whem address is added, I would like to add the lat and long to a hidden input but keep getting error? It works fine but everytime i add a field for lat it stops?

the code is

 <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
    <link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
    <style>
      #locationField, #controls {
        position: relative;
        width: 480px;
      }
      #autocomplete {
        position: absolute;
        top: 0px;
        left: 0px;
        width: 99%;
      }
      .label {
        text-align: right;
        font-weight: bold;
        width: 100px;
        color: #303030;
      }
      #address {
        border: 1px solid #000090;
        background-color: #f0f0ff;
        width: 480px;
        padding-right: 2px;
      }
      #address td {
        font-size: 10pt;
      }
      .field {
        width: 99%;
      }
      .slimField {
        width: 80px;
      }
      .wideField {
        width: 200px;
      }
      #locationField {
        height: 20px;
        margin-bottom: 2px;
      }
    </style>
  </head>

  <body>
    
<table id="address"> <tr> <td class="label">Street address</td> <td class="slimField"><input class="field" id="street_number" disabled="true"></input></td> <td class="wideField" colspan="2"><input class="field" id="route" disabled="true"></input></td> </tr> <tr> <td class="label">City</td> <!-- Note: Selection of address components in this example is typical. You may need to adjust it for the locations relevant to your app. See https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform --> <td class="wideField" colspan="3"><input class="field" id="locality" disabled="true"></input></td> </tr> <tr> <td class="label">State</td> <td class="slimField"><input class="field" id="administrative_area_level_1" disabled="true"></input></td> <td class="label">Zip code</td> <td class="wideField"><input class="field" id="postal_code" disabled="true"></input></td> </tr> <tr> <td class="label">Country</td> <td class="wideField" colspan="3"><input class="field" id="country" disabled="true"></input></td> </tr> </table> // This example displays an address form, using the autocomplete feature // of the Google Places API to help users fill in the information. // This example requires the Places library. Include the libraries=places // parameter when you first load the API. For example: // var placeSearch, autocomplete; var componentForm = { street_number: 'short_name', route: 'long_name', locality: 'long_name', administrative_area_level_1: 'short_name', country: 'long_name', postal_code: 'short_name' }; function initAutocomplete() { // Create the autocomplete object, restricting the search to geographical // location types. autocomplete = new google.maps.places.Autocomplete( /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')), {types: ['geocode']}); // When the user selects an address from the dropdown, populate the address // fields in the form. autocomplete.addListener('place_changed', fillInAddress); } function fillInAddress() { // Get the place details from the autocomplete object. var place = autocomplete.getPlace(); for (var component in componentForm) { document.getElementById(component).value = ''; document.getElementById(component).disabled = false; } // Get each component of the address from the place details // and fill the corresponding field on the form. for (var i = 0; i <script src="https://maps.googleapis


Source: stackoverflow-javascript

Angular2 [ngClass] – Combining direct binding with conditional classes

I currently have two different working implementations of [ngClass] on an element;

[ngClass]="{ selected: element.isSelected, highlighted: element.isHighlighted}"

and

[ngClass]="element.customClasses"

Is it possible to combine both of these approaches in the template, or do I have to create a method in my component to return an array of classes based on the logic above?

Thanks!


Source: stackoverflow-javascript

CSS rotation by 360 degrees

I want to rotate a rectangle by an angle of 360 degrees (or even > 360 degrees) using CSS. The center of the rotation is “right center”. If I use the following CSS code for a rotation by 180 degrees (and trigger the rotation with JavaScript) it works fine:

@keyframes rotation {
  from {
    -webkit-transform-origin: right center;
    transform-origin: right center;
    opacity: 1;
    -webkit-animation-timing-function: linear;
  }

to {
    -webkit-transform-origin: right center;
    transform-origin: right center;
    -webkit-transform: rotate3d(0, 0, 1, 180deg);
    transform: rotate3d(0, 0, 1, 180deg);
    opacity: 1;
    -webkit-animation-timing-function: linear;
  }
}

.rotation {
  animation-name: rotation;
}

However, if I replace the 180 degrees by an angle >= 360 degrees it won’t work anymore. For example in the case of 360 degrees nothing happens because the starting position is equal to the end position of the rotation.

How can I implement rotations by 360 degrees or more?


Source: stackoverflow-javascript

Display image using json

all work to fetch image src from my sql moving to js file till html work fine but iam wondering why the (pic) selector not display my image on the page

// this is my php file witch fetch all images from mysql databas related to marker selected

this is the result on browser

    <?php
    $dbhost = '127.0.0.1';
    $dbuser = 'root';
    $dbpass = '';
    $dbname = 'maalem';


    $sql2 = "SELECT img FROM image WHERE L_ID=:id";
    try {
        $con = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
        $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $con->query('SET NAMES utf8');
        $stmt = $con->prepare($sql2);  
        $stmt->bindParam("id", $_GET["L_ID"]);
        $stmt->execute();
        $img = $stmt->fetchAll(PDO::FETCH_OBJ); 
        $con = null;
        echo '{"pics":'. json_encode($img) .'}'; 
        } catch(PDOException $e) {
        echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    }
    ?>

//this is the javascript file 



    $('#detailsPage').live('pageshow', function (event) {
    var id = getUrlVars()["L_ID"];
    $.getJSON(serviceURL + 'getmarker.php?L_ID=' + id, displayimg);
    });


    function displayimg(data) {
     var imgs = data.pics;
     console.log(imgs);
    $('#pic').text('<img src="' + imgs.img + '"width=160 height=160/>');

    $('#actionList').listview('refresh');

     }


    function getUrlVars() {
    var vars = [],
    hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
     }

//HTML file 

   <!DOCTYPE HTML>
   <html>
    <head>
    </head>

    <body>

        

الوصف

</div> </div> </body> Source: stackoverflow-php

Query into wordpress db from laravel

I have setup my main application in laravel and set up word press for blog (CRUDE) operation. Installed wordpress inside public folder and configured database settings for 2nd database in config/database.php in laravel.

The trouble I’m having is how do i query in 2nd db (wordpress). I want to show latest 3 blog post with their featured image in landing page of my laravel app.

The main confusion is caused by one post has two rows in db (wordpress) with attributepost_status with values published for first row and inherit for second row. And 3 rows if featured image is set to blog post. I would be very helpful if anyone can walk through me from this problem.


Source: stackoverflow-php

check for duplicate results in multi dimensional array

I have a multi dimensional array and I need to cross check it for duplicate results and if they are duplicated remove the array with the duplicate results. I need to check 3 keys for duplication; number, departure and arrival. Here is an example array where the 3rd array is a duplicate and would need to be deleted:

[Cars] => Array
    (
        [0] => Array
            (
                [cartype] => car1
                [number] => 123
                [craft] => 456
                [departure] => GHY
                [departtime] => 20:25
                [arrival] => PUI
                [arrivetime] => 22:50
            )

        [1] => Array
            (
                [cartype] => car2
                [number] => 567
                [craft] => 890
                [departure] => LHY
                [departtime] => 16:25
                [arrival] => PGY
                [arrivetime] => 23:50
            )
        [2] => Array
            (
                [cartype] => car2
                [number] => 567
                [craft] => 890
                [departure] => LHY
                [departtime] => 16:25
                [arrival] => PGY
                [arrivetime] => 23:50
            )

    )

I would really appreciate some help.

Thanks,


Source: stackoverflow-php

PHP parse error with no explanation

PHP is giving me a parse error here.

if ($detalleReserva->isGratis() || $detalleReserva->isPasajeroSinCosto()){
    $cantPaxGratis++;
}

Parse error: parse error in /Library/WebServer/Documents/versioned/software/tur/liquidacionHead.php on line 58

The if line is line 58. I’ve tried changing de || with OR but the same. If I change the second part (after || ) for a ‘1’ or a ‘0’ it works fine.

Extra information:

function isPasajeroSinCosto() {
     return ($this->tipo == 4);
}

PHP version:

PHP 7.1.0 (cli) (built: Dec 2 2016 03:30:24) ( NTS )


Source: stackoverflow-php

Choosing programming platform/language: MQTT, DB & Webserver

I want to write a server application which is able to subscribe to an MQTT broker, store the data it receives in a database like MySQL and also present the data in a webpage, but I don’t know what the best setup would be for this.

Options I thought of:

  1. Separate programs for all steps: One which handles the connection between the MQTT broker in Java or something and another framework in a framework I’m familiar with like RoR or PHP.

  2. A complete package written in NodeJS which does everything self contained.

Which of these is the most efficient and/or flexible approach, or am I completely missing the mark and do you have a better solution?


Source: stackoverflow-php

Available modules in node script

why do I get different results when trying to find out more about the http module in node.js in the following to ways?

  1. If I enter the node REPL and then print the content of the http module, i.e. if I run

    me@mymachine:~> node
    > console.log(http)
    

    I get all the details of the http object:

    { IncomingMessage: { [Function: IncomingMessage] super_: {
    ...
    
  2. If I write a script file called, say, script.js containing the following single line

    console.log(http);
    

    and execute it by running

    node script.js
    

    I get

    ReferenceError: http is not defined
    

I would have expected both cases to behave in the same way – either the http module is preloaded or not. Why is there a difference? What am I getting wrong here?

I thought I could ‘fix’ this by preloading module http by running (in version 2)

node -r http script.js

Shouldn’t this preload module http and thus avoid the reference error?

Looking forward to your input!