Announcement

Collapse
No announcement yet.

Any simple examples of ajax use in module?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: Any simple examples of ajax use in module?

    It's the config for setting up my work space. Works just like config in MM; sets paths, global variables, etc.

    In this case, it's what defined where the ajax.mvc file is. But you can just hardcode it to make life easy.

    Comment


      #17
      Re: Any simple examples of ajax use in module?

      How goes the playing about? Make any cool advancements?

      Comment


        #18
        Re: Any simple examples of ajax use in module?

        Hello forum: Looking for help.
        I am using the following POST in my AJAX routine:

        xmlhttp.open("POST","h tt p:....php",true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("basket_id=307496&carrier=Roadrunner" );.


        It works OK with the coded constants for basket_id & carrier but I need to use my javascript variables instead.
        How should the send("....") be coded to use variables instead of constants?
        Thanks, Larry
        Last edited by sartaingerous; 07-28-17, 02:16 PM.
        Larry
        Luce Kanun Web Design
        www.facebook.com/wajake41
        www.plus.google.com/116415026668025242914/posts?hl=en


        Comment


          #19
          Re: Any simple examples of ajax use in module?

          I would think:

          xmlhttp.send("basket_id=" + b + "&carrier=" + c);

          -- where b and c are the variables. JS uses the plus sign for string concatenation (equivalent to the $ operator in Miva Script).
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #20
            Re: Any simple examples of ajax use in module?

            Hi Kent: Thanks for the reply. I decided to go with a GET instead of a POST and after looking at an example at http://www.w3schools.com/ajax/ajax_x...quest_send.asp came up with this:
            xmlhttp.open("GET","http://www.xxx.com/mm5/UpdateCarrier.php?basket_id=" + basket + "&carrier=" +carrier + "&t=" + Math.random(),true);

            Cheers, Larry
            Last edited by wajake41; 02-19-13, 10:12 AM.
            Larry
            Luce Kanun Web Design
            www.facebook.com/wajake41
            www.plus.google.com/116415026668025242914/posts?hl=en


            Comment


              #21
              Re: Any simple examples of ajax use in module?

              This is how we are using AJAX to update a table on our database and thanks to hostasaurus it's nearly iinstantaneous.
              When a <select <option is clicked, the onChange event executes the Update() function.
              <script type="text/javascript">
              function Update() {
              var basket = trimString(document.getElementById("basket_id").va lue);
              var carrier = trimString(document.getElementById("FreightMethod" ).value);
              if (carrier == "") {
              alert("Please select a carrier for this order.");
              document.getElementById("FreightMethod").focus();
              return false;
              }
              AJAXUpdateCarrier(basket,carrier); // update the shipping table
              return true;
              }
              function AJAXUpdateCarrier(basket,carrier){
              var xmlhttp;

              if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
              } else { // code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
              xmlhttp.onreadystatechange=function() {
              if (xmlhttp.readyState==4 && xmlhttp.status==200){
              document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
              alert("done");
              }
              }
              xmlhttp.open("GET","http://www.xxx.com/mm5/UpdateCarrier.php?basket_id=" + basket + "&carrier=" +carrier + "&t=" + Math.random(),true);
              xmlhttp.send();
              }
              </script>

              <body>
              <select name="FreightMethod"id="FreightMethod"style="display:block;"onChange="return Update()"
              <option value=""selected>Select a Carrier</option>
              <option value="Roadrunner">Roadrunner ($192.12)</option>
              <option value="YRC">YRC ($232.05)</option>
              <option value="R+L Carriers">R+L Carriers ($288.95)</option>
              <option value="Estes Express">Estes Express ($367.28)</option>
              </select>
              Last edited by wajake41; 02-19-13, 08:37 PM.
              Larry
              Luce Kanun Web Design
              www.facebook.com/wajake41
              www.plus.google.com/116415026668025242914/posts?hl=en


              Comment


                #22
                Re: Any simple examples of ajax use in module?

                Cool, I'm bookmarking this to refer back to for an upcoming project. Thanks!
                Kent Multer
                Magic Metal Productions
                http://TheMagicM.com
                * Web developer/designer
                * E-commerce and Miva
                * Author, The Official Miva Web Scripting Book -- available on-line:
                http://www.amazon.com/exec/obidos/IS...icmetalproducA

                Comment


                  #23
                  Re: Any simple examples of ajax use in module?

                  Hi Kent: Thanks for your reply.
                  This is my first AJAX routine and came mostly from the tutorial on the website you recommended at http://www.w3schools.com/ajax/ajax_examples.asp.

                  If anyone sees errors or ways to improve it, please offer your comments and advice.
                  Cheers, Larry
                  Larry
                  Luce Kanun Web Design
                  www.facebook.com/wajake41
                  www.plus.google.com/116415026668025242914/posts?hl=en


                  Comment


                    #24
                    Re: Any simple examples of ajax use in module?

                    A while ago, I wrote a beast of an object in JavaScript, which served as an AjaxQueue. The reason is, if you're doing multiple requests on a page, or if you have a slow server, you may end up overwriting a call that you made, thus never getting the response that you're looking for.

                    Here's the code, feel free to use it:
                    Code:
                    function getXMLHTTPRequest() 
                    {
                       var request = false;
                       try { request = new XMLHttpRequest();} // Firefox, etc., and newest IE
                       catch (err1)
                       {
                          try {request = new ActiveXObject("Msxml2.XMLHTTP"); } // Some versions IE
                          catch (err2)
                          {
                             try {request = new ActiveXObject("Microsoft.XMLHTTP");} // other versions IE
                             catch (err3) { request = false; }
                          }
                       }
                       return request;
                    }
                    
                    // Create the global request object
                    var myRequest = getXMLHTTPRequest();
                    
                    //TODO:        I need to rewrite the getXMLHTTPRequest functions with the prototype object, to cover cross-browser issues.
                    //             What I want to do is integrate the entire thing into the AJAXqueue
                    //             This way we can maintain multiple XMLHttpRequests (I believe the current simultaneous max is around 4)
                    //             And really get them all working with the AJAXqueue
                    //TODO:        AJAXqueue.requestPool = new Array() //Array of available requests
                    //TODO:        AJAXqueue.request = new XMLHttpRequest() // modified version of getXMLHttpRequest. Easier for updating and maintaining.
                    //TODO:        AJAXqueue.requests = new Array() //Array of requests that are currently being processed
                    //TODO:        AJAXqueue.process() // rewrite this function to use AJAXqueue.requestPool().
                    //
                        
                    // Due to the AJAXy nature of this... we're going to create a 'class' that will hold
                    // what we want to do via our AJAX interface ... we need to do this because we have
                    // to wait for everything to be done in order.  So we're setting up a queue.
                    function AJAXqueue() 
                    {
                       // here's our 'heap' of calls we have to make
                       this.heap = new Array();
                       // For easy adding of calls
                       this.addRequest = function(JSONObject) { this.heap.push(new AJAXqueueNode(JSONObject)); }
                       // Function to process the queue
                       this.process = function() { this.heap[0].doRequest(this); }
                        
                       // Here is our AJAXqueueNode object.  Pretty cool that you can keep objects within objects
                       // The AJAXqueueNode object isn't accessible outside of AJAXqueue.  Neat!
                       function AJAXqueueNode(JSONObject) 
                       {
                          for (var key in JSONObject) 
                          {
                             if (JSONObject.hasOwnProperty(key)) 
                             {
                                switch(key) 
                                {
                                   case 'uninitialized': this.uninitialized = JSONObject[key]; break;
                                   case 'loading':       this.loading       = JSONObject[key]; break;
                                   case 'loaded':        this.loaded        = JSONObject[key]; break;
                                   case 'interactive':   this.interactive   = JSONObject[key]; break;
                                   case 'completed':     this.completed     = JSONObject[key]; break;
                                   case 'method':        this.method        = JSONObject[key].toUpperCase(); break;
                                   case 'params':        this.params        = JSONObject[key]; break;
                                   case 'url':           this.url           = JSONObject[key]; break;
                                   case 'requestType':   this.requestType   = JSONObject[key]; break;
                                   default: break;
                                }
                             }
                          }
                    
                          this.doRequest = function (queue) 
                          {
                             var random = parseInt(Math.random()*99999999);
                             if(this.method == 'GET') myRequest.open(this.method, this.url + '?' + this.params + "&rand="+random, this.requestType);
                             var request = this;
                             myRequest.onreadystatechange = function() 
                             {
                                switch(this.readyState) 
                                {
                                   case 0: if(typeof request.uninitialized == 'function') { request.uninitialized(this); } break;
                                   case 1: if(typeof request.loading       == 'function') { request.loading(this);       } break;
                                   case 2: if(typeof request.loaded        == 'function') { request.loaded(this);        } break;
                                   case 3: if(typeof request.interactive   == 'function') { request.interactive(this);   } break;
                                   case 4: if(typeof request.completed     == 'function') { request.completed(this);     } break;
                                }
                    
                                if (myRequest.readyState == 4) 
                                {
                                   if (myRequest.status != 200) { alert("AJAXreceive error: " + myRequest.statusText); }
                                   else   // success!:
                                   {
                                      queue.heap.shift();
                                      queue.process();                        
                                   }
                                }
                             }
                             myRequest.send(null); // null for GET requests, encoded stuff for POST requests
                          }
                       }
                       //Define defaults
                       AJAXqueueNode.prototype.ASYNCHRONOUS = true;
                       AJAXqueueNode.prototype.SYNCHRONOUS  = false;
                       AJAXqueueNode.prototype.requestType  = AJAXqueueNode.prototype.ASYNCHRONOUS;
                       AJAXqueueNode.prototype.params       = 'abc=123';
                       AJAXqueueNode.prototype.method       = 'GET'
                       //returns the size of the current AJAXqueue
                       this.size = function () { return this.heap.length; }
                    }
                    
                    /********************
                    Example of how to use.
                    
                    ********************/
                    //Create the queue
                    var queue = new AJAXqueue();
                    
                    // Add the requests.  Each request is in JSON (this is an arbitrary object)
                    // The object needs a 'url' parameter.  That's just the script you're hitting
                    // The rest of the params are optional
                    queue.addRequest(
                    {
                      'url'      : 'lesson5/weatherxml.php',
                      'completed': function (obj)
                          {
                             responseXML = obj.responseXML;
                             // Get the location
                             var locations = responseXML.getElementsByTagName('location');
                             var location  = locations[0].firstChild.nodeValue;
                             // Get the Temperature
                             var temps = responseXML.getElementsByTagName('temperature_string');
                             var temp  = temps[0].firstChild.nodeValue;
                             // Get the Image base
                             var images_base = responseXML.getElementsByTagName('icon_url_base');
                             var image_base = images_base[0].firstChild.nodeValue;
                             // Get the image
                             var images = responseXML.getElementsByTagName('icon_url_name');
                             var image = images[0].firstChild.nodeValue;
                    
                             var image_location = image_base + image;
                    
                             var result ='<h3>' + location + '</h3>' + '<img src="' + image_location + '" /><br />' + temp;
                             document.getElementById('weather').innerHTML = result;
                          }
                       }
                    );
                    Last edited by titus; 02-26-13, 01:48 PM. Reason: Cleaned up code to look nicer.
                    PCINET, LLC

                    Miva Merchant Design, Development, Integration & Support
                    We built the most Miva Merchant stores!
                    Miva shopping cart design & integration service and our Portfolio!

                    e-mail: [email protected]
                    web: www.pcinet.com

                    "We who cut mere stones must always be envisioning cathedrals."
                    Quarry Worker's Creed

                    Comment


                      #25
                      Re: Any simple examples of ajax use in module?

                      Interesting. I'm a little confused by the use of the variable "this" in the AJAXqueue function. I thought that "this" was used to refer to document elements, such as a piece of text or a form input. What does it refer to here?

                      Thanks --
                      Kent Multer
                      Magic Metal Productions
                      http://TheMagicM.com
                      * Web developer/designer
                      * E-commerce and Miva
                      * Author, The Official Miva Web Scripting Book -- available on-line:
                      http://www.amazon.com/exec/obidos/IS...icmetalproducA

                      Comment


                        #26
                        Re: Any simple examples of ajax use in module?

                        Not sure if my last post posted...

                        I'll try again.

                        Basically, 'this' is used for context. It's referring to the current object that you're working within. In JavaScript, functions are objects. That's why you can throw a name to an anonymous function, like so:
                        Code:
                        var sayHi = function () { alert("Hi!"); };
                        The variables, functions and objects all work well together. JavaScript is a prototypal based language, and the scope of it works differently than most languages we're used to. For instance, in JavaScript, scope is based on the function level, not the brace level.

                        Also, the JavaScript preprocessors will move your var statements to the top of the function declaration. So you can get some tricky errors to resolve, when you're trying to assign a value with a 'var' variable declaration which needs to be in a specific spot of the program. It sort of bubbles/elevates to the top, and the developers are left in tears and tremors.
                        PCINET, LLC

                        Miva Merchant Design, Development, Integration & Support
                        We built the most Miva Merchant stores!
                        Miva shopping cart design & integration service and our Portfolio!

                        e-mail: [email protected]
                        web: www.pcinet.com

                        "We who cut mere stones must always be envisioning cathedrals."
                        Quarry Worker's Creed

                        Comment


                          #27
                          Re: Any simple examples of ajax use in module?

                          Hello,

                          I have here a simple example of how a mivascript module uses json, javascript and ajax. This example calls a JSON function in runtime and in the admin interface.

                          On a Utilities Tab called JSON Example I created a button with an onclick javascript function. This javascript function can gather any variables and pass them to a function I called Example_Function. This function is defined within Module_Clientside. When that function is called it will invoke my JSON function which I called JSON_Example_Function. Inside this function you can do whatever server side logic you need to implement and then return a proper JSON response. Upon a successful response I output "Successfully called a JSON function".

                          This sequence is also set up using the component API, which can be used in runtime.

                          Let me know if you have any further questions.

                          Kyle Hansen
                          Miva Merchant Software Developer

                          Code:
                          <MvINCLUDE FILE = "build_ident.mv">
                          
                          
                          <MvCOMMENT>
                          |
                          | Miva Merchant v5.x
                          |
                          | This file and the source codes contained herein are the property of
                          | Miva Merchant, Inc.  Use of this file is restricted to the specific terms and
                          | conditions in the License Agreement associated with this file.  Distribution
                          | of this file or portions of this file for uses not covered by the License
                          | Agreement is not allowed without a written agreement signed by an officer of
                          | Miva Merchant, Inc.
                          |
                          | Copyright 1998-2013 Miva Merchant, Inc.  All rights reserved.
                          | http://www.mivamerchant.com
                          |
                          | Prefix         : MER-JSN-EXM-
                          | Next Error Code: 1   
                          |
                          </MvCOMMENT>
                          
                          
                          <MvFUNCTION NAME = "Module_Description" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvASSIGN NAME = "l.module:code"       VALUE = "json_example">
                              <MvASSIGN NAME = "l.module:name"       VALUE = "JSON Example">
                              <MvASSIGN NAME = "l.module:provider"   VALUE = "Miva Merchant">
                              <MvASSIGN NAME = "l.module:version"    VALUE = "1.0000">
                              <MvASSIGN NAME = "l.module:api_ver"    VALUE = "5.70">
                              <MvASSIGN NAME = "l.module:features"   VALUE = "util, vis_util, json, clientside, component">
                          </MvFUNCTION>
                          
                          
                          <MvCOMMENT>
                          |
                          | Feature util
                          |
                          </MvCOMMENT>
                          
                          
                          <MvFUNCTION NAME = "StoreUtilityModule_Action" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "StoreUtilityModule_LeftNavigation" PARAMETERS = "module var, indent" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "StoreUtilityModule_Screen" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "StoreUtilityModule_Validate" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvCOMMENT>
                          |
                          | Feature util
                          |
                          </MvCOMMENT>
                          
                          
                          <MvFUNCTION NAME = "Module_Utility_Content" PARAMETERS = "module var, tab, load_fields" STANDARDOUTPUTLEVEL = "text, html, compresswhitespace">
                              <MvIF EXPR = "{ g.Tab NE 'JSON_EXAMPLE' }">
                                  <MvFUNCTIONRETURN VALUE = 1>
                              </MvIF>
                              
                              <input type="button" id="json_example_button" value="Call JSON Function" onclick="Call_Json_Function()" />
                              
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "Module_Utility_Head" PARAMETERS = "module var, tab" STANDARDOUTPUTLEVEL = "text, html, compresswhitespace">
                              <MvIF EXPR = "{ g.Tab NE 'JSON_EXAMPLE' }">
                                  <MvFUNCTIONRETURN VALUE = 1>
                              </MvIF>
                          
                          
                              <MvASSIGN NAME = "g.MivaVM_API"         VALUE = "{ s.apitype }">
                              <MvASSIGN NAME = "g.MivaVM_Version"     VALUE = "{ s.mivaversion }">
                          
                          
                              <MvEVAL EXPR = "{ [ g.Module_Admin ].JavaScript_SetVariables( 'g', 'adminurl, sessionurl, clientside_url, json_url, MivaVM_API, MivaVM_Version, AdminGraphics_Path, Store_Code' ) }">
                          
                          
                              <script language="JavaScript" src="{ g.clientside_url $ 'Filename=ajax.js' }"></script>
                              <script language="JavaScript" src="{ g.clientside_url $ 'Module_Code=' $ encodeattribute( l.module:code ) $ '&M=' $ Module_Version_Token() $ '&Filename=json_example.js' }"></script>
                          
                          
                              <script type="text/javascript">
                                  function Call_Json_Function()
                                  {
                                      Example_Function( function( response ) { Example_Function_Callback( response ); } );
                                  }
                                  
                                  function Example_Function_Callback( response )
                                  {
                                      if ( !response.success )
                                      {
                                          return alert( response.error_message );
                                      }
                                      
                                      alert( 'Successfully called a JSON function' );
                                  }
                              </script>
                              
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "Module_Utility_Tabs" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = "JSON_EXAMPLE:JSON Example">
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "Module_Utility_Update" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">    
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "Module_Utility_Validate" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvCOMMENT>
                          |
                          | Feature json
                          |
                          </MvCOMMENT>
                          
                          
                          <MvFUNCTION NAME = "Module_JSON" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvIF EXPR = "{ g.Module_Function EQ 'Example_Function' }"> <MvFUNCTIONRETURN VALUE = "{ JSON_Example_Function( l.module ) }"> </MvIF>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "JSON_Example_Function" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvIF EXPR = "{ NOT [ g.Module_JSON ].JSON_Store_Open() }"> <MvFUNCTIONRETURN> </MvIF>
                              
                              <MvFUNCTIONRETURN VALUE = "{ [ g.Module_JSON ].JSON_Response_Success() }">
                          </MvFUNCTION>
                          
                          
                          <MvCOMMENT>
                          |
                          | Feature 'clientside'
                          |
                          </MvCOMMENT>
                          
                          
                          <MvFUNCTION NAME = "Module_Clientside" PARAMETERS = "module var" STANDARDOUTPUTLEVEL = "">
                              <MvIF EXPR = "{ g.Filename EQ 'json_example.js' }"> 
                                  <MvEVAL EXPR = "{ Compatibility_Module_Content_Type( l.module, 'text/javascript' ) }">
                                  <MIVA STANDARDOUTPUTLEVEL = "text,html"> 
                                      function Example_Function( callback )
                                      {
                                          return AJAX_Call_Module(    callback, 
                                                                      'admin', 
                                                                      '<MvEVAL EXPR = "{ g.Encoded_Module_Code }">', 
                                                                      'Example_Function' );
                                      }
                                  <MIVA STANDARDOUTPUTLEVEL = "">
                              <MvELSE>
                                  <MvASSIGN NAME = "l.null" VALUE = "{ miva_output_header( 'Status', '404 Not Found' ) }">
                              </MvIF>
                          </MvFUNCTION>
                          
                          
                          <MvCOMMENT>
                          |
                          |    Feature component
                          |
                          </MvCOMMENT>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Tabs" PARAMETERS = "module var, item, settings var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = "">
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Validate" PARAMETERS = "module var, item, field_prefix, fields var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Update" PARAMETERS = "module var, item, field_prefix, fields var, settings var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Content" PARAMETERS = "module var, item, tab, load_fields, field_prefix, fields var, settings var" STANDARDOUTPUTLEVEL = "">
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Defaults" PARAMETERS = "module var, settings var" STANDARDOUTPUTLEVEL = "">
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Page_Assign" PARAMETERS = "module var, page var, item, settings var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Page_Unassign" PARAMETERS = "module var, page var, item, settings var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Initialize" PARAMETERS = "module var, item, all_settings var, settings var" STANDARDOUTPUTLEVEL = "">
                              <MvFUNCTIONRETURN VALUE = 1>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Prerender" PARAMETERS = "module var, item, all_settings var, settings var, param" STANDARDOUTPUTLEVEL = "">
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Render_Start" PARAMETERS = "module var, item, all_settings var, settings var, param" STANDARDOUTPUTLEVEL = "">
                              <MvIF EXPR = "{ JSON_Example_Function( l.module ) }">
                                  <MvEVAL EXPR = "Successfully called a JSON function">
                              </MvIF>
                          </MvFUNCTION>
                          
                          
                          <MvFUNCTION NAME = "ComponentModule_Render_End" PARAMETERS = "module var, item, all_settings var, settings var, param" STANDARDOUTPUTLEVEL = "">
                          </MvFUNCTION>
                          
                          
                          <MvINCLUDE FILE = "includes/compatibility.mv">
                          [I]Kyle Hansen

                          Comment


                            #28
                            Re: Any simple examples of ajax use in module?

                            Kyle,

                            Let's say I have the JSON data formatted and ready to use at http://www.pinemporium.com/mm5/merch...E&Screen=AUTO3

                            Is there an easy, brief script to retrieve that data? I have tried at least a hundred different examples I found via Google and none work. I've tried to use the built in API functions and avoid jquery, but am not seeing how that is possible as they are very hard to follow and some files seem to be missing from the LSK.
                            Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
                            Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
                            Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
                            Facebook http://www.facebook.com/EmporiumPlus
                            Twitter http://twitter.com/emporiumplus

                            Comment


                              #29
                              Re: Any simple examples of ajax use in module?

                              If the JSON data is passed back as a JSON response. Then you will be able to retrieve it with javascript with response.data.
                              In your example it would be
                              Code:
                              var mydata_array = response.data.mydata;
                              in javascript.

                              You will be able to loop through your data with javascript.

                              Does this help?

                              -Kyle

                              [I]Kyle Hansen

                              Comment


                                #30
                                Re: Any simple examples of ajax use in module?

                                Kyle,

                                The problem I am having is trying to retrieve that response. No matter what I put in the javascript on the originating page, nothing comes through. I can hard code the array you saw at http://www.pinemporium.com/mm5/merch...E&Screen=AUTO3 in the origination page and I can access a specific member. But I have not been able to pull the data off the target page successfully. This page http://www.pinemporium.com/mm5/merch...E&Screen=JSON3 creates two variables, myJSONObject and myJSONObject2. The second is hard coded and works. The first is one of the attempts I tried to read the target page. It does not work. Do you see where I went wrong?
                                Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
                                Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
                                Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
                                Facebook http://www.facebook.com/EmporiumPlus
                                Twitter http://twitter.com/emporiumplus

                                Comment

                                Working...
                                X