Alpha DevCon 2018
Results 1 to 4 of 4

Thread: Returning JSON Data from remote Server using a Button's JavaScript on Click Event

  1. #1
    Member
    Real Name
    Mark Moss
    Join Date
    Jun 2010
    Posts
    101

    Post Returning JSON Data from remote Server using a Button's JavaScript on Click Event

    Help

    I have been stuck on this for over a week and admit that I need some HELP.

    I am trying to return a JSON data file from a Remote WEB Server and I am getting the following error "Uncaught ReferenceError: processJSON is not defined".

    The JSON data is being returned but it is not running the processJSON function. I am viewing the results in Google JavaScript Console.

    The code is in the onClick JavaScript event of a button on a UX form.

    Any HELP would be greatly appreciated


    Mark Moss




    function loadJSON(url) {
    var headID = document.getElementsByTagName("head")[0];
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = url;
    headID.appendChild(newScript);
    }

    function processJSON(feed){
    document.writeln(feed.makeName+'<BR>');
    }

    loadJSON('http://api.edmunds.com/v1/api/toolsrepository/vindecoder?vin=5NPET4AC2AH624786&api_key=8xgy9vtfr4pk2r7rf3phxr73&fmt=json&callback=processJSON');

  2. #2
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,301

    Default Re: Returning JSON Data from remote Server using a Button's JavaScript on Click Even

    Your processJSON function is defined inside the onClick JavaScript event for the button. loadJSON adds a call to processJSON in the head of your document.

    Code:
    <head>
       processJSON(...) being called
    </head>
    <body>
      <!-- but processJSON is defined inside the onClick event for some input object! That's no good -->
      <input type="some element..." onClick="function loadJSON(...) {...} function processJSON(...) {...} loadJSON('...');" ...>
    </body>
    <head> doesn't know that it needs to look inside the onClick attribute for one of the elements in your DOM to find the definition for processJSON.

    Here's someone else who had the same problem: http://stackoverflow.com/questions/5...-readyfunction

    You need to move your processJSON function outside the onClick function. There's a Code > Javascript Functions section for Grids & Dialogs...

    ---
    Sarah

  3. #3
    Member
    Real Name
    Mark Moss
    Join Date
    Jun 2010
    Posts
    101

    Default Re: Returning JSON Data from remote Server using a Button's JavaScript on Click Even

    Sarah

    Thank you so very much for your reply, it fixed the problem that I was having.


    Mark

  4. #4
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,301

    Default Re: Returning JSON Data from remote Server using a Button's JavaScript on Click Even

    You're welcome!

    And know that when you get JavaScript errors that searching StackOverflow.com (add site:stackoverflow.com to your google query) is an EXCELLENT resource.

    ---
    Sarah

Similar Threads

  1. click a button from javascript
    By Clipper87 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 27
    Last Post: 03-22-2013, 05:31 PM
  2. Local Server posts DATE data to SQL but Remote Server does not
    By AAVasaris in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 12-17-2012, 11:22 AM
  3. xbasic event for button click dialog
    By chadbrown in forum Application Server Version 11 - Web/Browser Applications
    Replies: 7
    Last Post: 09-13-2012, 10:19 AM
  4. v11 issue with button in embedded browse click event code
    By Mike Wilson in forum Alpha Five Version 11 - Desktop Applications
    Replies: 3
    Last Post: 03-08-2012, 11:47 AM
  5. Video : Calling a button onclick event in Javascript
    By Bob Moore in forum Application Server Version 10 - Web/Browser Applications
    Replies: 4
    Last Post: 02-19-2010, 03:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •