0

I'm trying to display data from an external JSON, and I'm practicing based on an example from a few years ago where the data isn't external: http://jsfiddle.net/axrwkr/5t5fj/50/

Here is my attempt, referencing an external JSON, on jsfiddle: http://jsfiddle.net/54sqn/4/

I have had success using Leaflet's L.GeoJson for other purposes (declaring the string array in the external file), but ultimately I would like to use ko.mapping to display/allow editing of a standard JSON. Anyway, I have scoured for just a basic example like this to display one entry from an external JSON in a straightforward way, and I can't seem to find an actual working example. I have seen so many more advanced examples, that I think I've mixed things up. Thank you for the help!

==============

JavaScript:

var viewModel = {};

$.getJSON("http://yourjavascript.com/348728012/temp.js", function (data) {
   viewModel.model = ko.mapping.fromJSON(data);
   ko.applyBindings(viewModel);
});

`

HTML:

Full Name: <input data-bind="value: fullName" disabled="disabled" /><br />
Ref: <input data-bind="value: referenceNumber" disabled="disabled" /><br />
Position: <input data-bind="value: position" disabled="disabled" /><br />
Email: <input data-bind="value: email" disabled="disabled" /><br />
Dept: <input data-bind="value: departmentName" disabled="disabled" /><br />
Country: <input data-bind="value: country" disabled="disabled" /><br />
Scott
  • 1
  • Open up your browser's dev tools and you should see an error about that temp.js request failing because it's from another site and you're not fetching it from a script tag. – JohnnyHK Aug 02 '14 at 04:20
  • It violates the same domain policy. You need to add a callback: http://stackoverflow.com/questions/3873636/no-response-from-mediawiki-api-using-jquery – Phil C Aug 02 '14 at 04:28
  • Thank you, I got it working! I also needed to change `ko.mapping.fromJSON` to `ko.mapping.fromJS` as seen here: http://stackoverflow.com/a/12575062/3901304 I'm on my way now! – Scott Aug 02 '14 at 05:18

1 Answers1

0

hi you data not comming from temp.js file. may be not proper JSON data.

enter image description here

gaurav
  • 210
  • 1
  • 6