select2 js does not displaying result from json fileWhy does Google prepend while(1); to their JSON responses?Why can't Python parse this JSON data?Returning JSON from a PHP ScriptPosting a File and Associated Data to a RESTful WebService preferably as JSONHow to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Using Node.JS, how do I read a JSON file into (server) memory?How do I write JSON data to a file?How to prettyprint a JSON file?Reading JSON from a file?jquery select2 (4.0) ajax with templateResult and templateSelection
Why Shazam when there is already Superman?
How do apertures which seem too large to physically fit work?
How do you make your own symbol when Detexify fails?
Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset
Creepy dinosaur pc game identification
Is this toilet slogan correct usage of the English language?
Can I visit Japan without a visa?
What are the advantages of simplicial model categories over non-simplicial ones?
What is Cash Advance APR?
What is the highest possible scrabble score for placing a single tile
Does IPv6 have similar concept of network mask?
Terse Method to Swap Lowest for Highest?
15% tax on $7.5k earnings. Is that right?
How does a computer interpret real numbers?
Pre-mixing cryogenic fuels and using only one fuel tank
How to fade a semiplane defined by line?
Is aluminum electrical wire used on aircraft?
Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?
How can "mimic phobia" be cured or prevented?
Why is the "ls" command showing permissions of files in a FAT32 partition?
What is going on with 'gets(stdin)' on the site coderbyte?
Limits and Infinite Integration by Parts
What if a revenant (monster) gains fire resistance?
Redundant comparison & "if" before assignment
select2 js does not displaying result from json file
Why does Google prepend while(1); to their JSON responses?Why can't Python parse this JSON data?Returning JSON from a PHP ScriptPosting a File and Associated Data to a RESTful WebService preferably as JSONHow to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Using Node.JS, how do I read a JSON file into (server) memory?How do I write JSON data to a file?How to prettyprint a JSON file?Reading JSON from a file?jquery select2 (4.0) ajax with templateResult and templateSelection
I've created a file faqs.json from file_put_contents
and resulted as correctly (see fig.1). However, when I am trying to render it using "Select2 JS" it always end up: "The results could not be loaded", which I just follow the given instructions at the website. 1 thing I cannot understand is how to pull the post_title
and post_name
from the json file. I believe I am missing something here.
Note: json file content was fetched from "custom post type" of wordpress
Here's my sample json file.
Fig.1
[
"ID": 1336,
"post_title": "test",
"post_status": "publish",
"post_name": "test",
"post_excerpt": ""
"ID": 1335,
"post_title": "What are the requirements for",
"post_status": "publish",
"post_name": "what-are-the-requirements-for",
"post_excerpt": ""
]
Here's my javascript file.
Fig.2
function formatRepo (repo)
if (repo.loading) return repo.text;
var markup = '<div class="clearfix">' +
'<div class="col-sm-1">' +
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
'</div>' +
'<div clas="col-sm-10">' +
'<div class="clearfix">' +
'<div class="col-sm-6">' + repo.full_name + '</div>' +
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
'<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
'</div>';
if (repo.description)
markup += '<div>' + repo.description + '</div>';
markup += '</div></div>';
return markup;
function formatRepoSelection (repo)
$(document).ready(function()
$(".js-data-example-ajax").select2(
ajax:
url: $json + "faqs.json",
dataType: 'json',
delay: 250,
data: function (params)
return
q: params.term, // search term
page: params.page
;
,
processResults: function (data, page)
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return
results: data.items
;
,
cache: true
,
escapeMarkup: function (markup) return markup; , // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
);
);
javascript json
add a comment |
I've created a file faqs.json from file_put_contents
and resulted as correctly (see fig.1). However, when I am trying to render it using "Select2 JS" it always end up: "The results could not be loaded", which I just follow the given instructions at the website. 1 thing I cannot understand is how to pull the post_title
and post_name
from the json file. I believe I am missing something here.
Note: json file content was fetched from "custom post type" of wordpress
Here's my sample json file.
Fig.1
[
"ID": 1336,
"post_title": "test",
"post_status": "publish",
"post_name": "test",
"post_excerpt": ""
"ID": 1335,
"post_title": "What are the requirements for",
"post_status": "publish",
"post_name": "what-are-the-requirements-for",
"post_excerpt": ""
]
Here's my javascript file.
Fig.2
function formatRepo (repo)
if (repo.loading) return repo.text;
var markup = '<div class="clearfix">' +
'<div class="col-sm-1">' +
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
'</div>' +
'<div clas="col-sm-10">' +
'<div class="clearfix">' +
'<div class="col-sm-6">' + repo.full_name + '</div>' +
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
'<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
'</div>';
if (repo.description)
markup += '<div>' + repo.description + '</div>';
markup += '</div></div>';
return markup;
function formatRepoSelection (repo)
$(document).ready(function()
$(".js-data-example-ajax").select2(
ajax:
url: $json + "faqs.json",
dataType: 'json',
delay: 250,
data: function (params)
return
q: params.term, // search term
page: params.page
;
,
processResults: function (data, page)
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return
results: data.items
;
,
cache: true
,
escapeMarkup: function (markup) return markup; , // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
);
);
javascript json
add a comment |
I've created a file faqs.json from file_put_contents
and resulted as correctly (see fig.1). However, when I am trying to render it using "Select2 JS" it always end up: "The results could not be loaded", which I just follow the given instructions at the website. 1 thing I cannot understand is how to pull the post_title
and post_name
from the json file. I believe I am missing something here.
Note: json file content was fetched from "custom post type" of wordpress
Here's my sample json file.
Fig.1
[
"ID": 1336,
"post_title": "test",
"post_status": "publish",
"post_name": "test",
"post_excerpt": ""
"ID": 1335,
"post_title": "What are the requirements for",
"post_status": "publish",
"post_name": "what-are-the-requirements-for",
"post_excerpt": ""
]
Here's my javascript file.
Fig.2
function formatRepo (repo)
if (repo.loading) return repo.text;
var markup = '<div class="clearfix">' +
'<div class="col-sm-1">' +
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
'</div>' +
'<div clas="col-sm-10">' +
'<div class="clearfix">' +
'<div class="col-sm-6">' + repo.full_name + '</div>' +
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
'<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
'</div>';
if (repo.description)
markup += '<div>' + repo.description + '</div>';
markup += '</div></div>';
return markup;
function formatRepoSelection (repo)
$(document).ready(function()
$(".js-data-example-ajax").select2(
ajax:
url: $json + "faqs.json",
dataType: 'json',
delay: 250,
data: function (params)
return
q: params.term, // search term
page: params.page
;
,
processResults: function (data, page)
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return
results: data.items
;
,
cache: true
,
escapeMarkup: function (markup) return markup; , // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
);
);
javascript json
I've created a file faqs.json from file_put_contents
and resulted as correctly (see fig.1). However, when I am trying to render it using "Select2 JS" it always end up: "The results could not be loaded", which I just follow the given instructions at the website. 1 thing I cannot understand is how to pull the post_title
and post_name
from the json file. I believe I am missing something here.
Note: json file content was fetched from "custom post type" of wordpress
Here's my sample json file.
Fig.1
[
"ID": 1336,
"post_title": "test",
"post_status": "publish",
"post_name": "test",
"post_excerpt": ""
"ID": 1335,
"post_title": "What are the requirements for",
"post_status": "publish",
"post_name": "what-are-the-requirements-for",
"post_excerpt": ""
]
Here's my javascript file.
Fig.2
function formatRepo (repo)
if (repo.loading) return repo.text;
var markup = '<div class="clearfix">' +
'<div class="col-sm-1">' +
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
'</div>' +
'<div clas="col-sm-10">' +
'<div class="clearfix">' +
'<div class="col-sm-6">' + repo.full_name + '</div>' +
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
'<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
'</div>';
if (repo.description)
markup += '<div>' + repo.description + '</div>';
markup += '</div></div>';
return markup;
function formatRepoSelection (repo)
$(document).ready(function()
$(".js-data-example-ajax").select2(
ajax:
url: $json + "faqs.json",
dataType: 'json',
delay: 250,
data: function (params)
return
q: params.term, // search term
page: params.page
;
,
processResults: function (data, page)
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return
results: data.items
;
,
cache: true
,
escapeMarkup: function (markup) return markup; , // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
);
);
javascript json
javascript json
asked Mar 8 at 2:17
iMarkDesignsiMarkDesigns
69621023
69621023
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055787%2fselect2-js-does-not-displaying-result-from-json-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055787%2fselect2-js-does-not-displaying-result-from-json-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown