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













0















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

);
);









share|improve this question


























    0















    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

    );
    );









    share|improve this question
























      0












      0








      0


      1






      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

      );
      );









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 2:17









      iMarkDesignsiMarkDesigns

      69621023




      69621023






















          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
          );



          );













          draft saved

          draft discarded


















          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















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme