Announcement

Collapse
No announcement yet.

Any simple examples of ajax use in module?

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

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

    No solution yet. I set that one aside and worked on other things for a while; I was getting frustrated. I may rewrite my code using jQuery, or I may load in Kyle's example module and try that. Speaking of which: the example uses a file called ajax.js, but I've been looking around my store with FTP, and I can't find that file. Does anyone know what folder it's in?

    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


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

      Hey Kent,

      Make sure you're not violating the Same-Origin Policy. The www, and https are different than example.com and http://example.com

      That was an issue for me before. I had similar symptoms.
      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


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

        Bingo! I had written http: in my script, but was viewing the page with an https: URL. I deleted the "s" and hit the Refresh button, and it worked on the first try. Thank you thank you thank you ...
        Last edited by Kent Multer; 03-14-13, 01:41 PM.
        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


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

          Originally posted by Kent Multer View Post
          Bingo! I had written http: in my script, but was viewing the page with an https: URL. I deleted the "s" and hit the Refresh button, and it worked on the first try. Thank you thank you thank you ...
          Glad I could help (:

          You can also look into CORS (Cross-Origin Resource Sharing) to help you get past the Same-Origin Policy with JavaScript and XmlHttpRequests. That is the safest way to do it.

          The other alternatives to making a call to a domain which you aren't on would be with an iframe, or with JSON-P.

          JSON-P stands for JSON with Padding. Basically, you set up a script tag with the src set to the URL you want to call.

          When you get the response, you eval it, and it will execute what you requested.

          Now, there are a few things here to look at. The server you're requesting data from has to have the wrapper function send you the data that you're requesting. Otherwise your eval won't process/evaluate anything. So, they have to comply on their side.

          The other thing to look at is that these types of requests expose the ENTIRE DOM to the site you're requesting from.

          That means they have access to cookies, and data stored on the page. That's not secure at all.

          If you're even the least bit security savvy or server savvy, you can set up Man in the Middle attacks to show just how insecure these types of calls are. So, saying that, I'm not sure if this would break PCI compliance if you're doing these types of calls when sensitive information is being requested and transmitted.

          I don't use any JSON-P with my modules and web applications that I write (if I can help it), specifically because I don't always know who I can trust, or if they have a secure server. I might be overly paranoid, though.
          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


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

            Hi titus: In my AJAX requests, I'm using POSTs like this:

            xmlhttp.open("POST","http://dev.myprogram.com/mm5/myPHPprogram.php",true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
            xmlhttp.send(msg);

            Does this expose the client's DOM? We are not passing sensative information unless bill to & ship to data is considered sensative.
            Is there a way to protect the client's DOM when using AJAX. BTW, I'm not using JSOM in my AJAX requests, the server response is a delimited string.
            Larry
            Larry
            Luce Kanun Web Design
            www.facebook.com/wajake41
            www.plus.google.com/116415026668025242914/posts?hl=en


            Comment


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

              If you're using a regular XmlHttpRequest (looks like you are), then you're going to be fine. JavaScript and browsers have something called the "Same-Origin Policy", which means, any request to a site which isn't of the same origin is stopped immediately. The only way around this is to use JSON-P, or to use CORS (Cross-Origin Resource Sharing). CORS works by sending specific headers to the server you're trying to talk to, and then the server will typically look over the request, see if the domain is on their whitelist of "Okay" domains, and then give a response.

              JSON-P, is actually calling a third party website, but not with an XmlHttpRequest. It's looking at it with the src attribute of the SCRIPT HTML tag. So it's different in the way that it connects to the site (from what I know, I could be wrong though).

              If the site that you're working from is dev.myprogram.com you're fine, as the domain is the same.

              It doesn't matter what server/engine is processing the request (Apache, nginX, G-WAN, Cherokee, empressa, etc), as it is concerned about the domain it's connecting to, not the service which is handling the connection.

              Think of it like a mail man delivering a piece of mail. He needs to have the right address, that's all that matters. If the letter is written in french, it's up to the people at the address to get it to the right person.

              With servers, you have different "listeners", which "listen" on different ports. When you have an IP address and a port, you have what is called a socket. The Same-Origin Policy is dependent upon the same socket. So you can't have an Ajax request going to www.example.com:8080/cool_response.php, being requested from www.example.com/ajax_demo.php.

              The default http port is 80. So, for the sake of simplicity, browsers don't put that up there, since it's assumed.

              What that means is that Apache, or the engine/service which is handling the HTTP connections, is listening to port 80.

              The reason I'm going into all of this, is because of the way that Empressa is configured. If you look at your .htaccess file, you'll see something in there called a "handler" and a "type".

              AddType application/x-miva-compiled .mvc
              Action application/x-miva-compiled /cgi-bin/mivavm

              That's saying to apache, "Hey, we're going to handle these specific files in this specific way." So all requests to a .mvc file (even URL rewritten requests, with the file extensions removed) will be handled by the virtual machine (/cgi-bin/mivavm) on the server. This allows empressa and apache walk hand-in-hand into the sunset.

              The handling of the .php files will probably be in the httpd.conf file or possibly in the .htaccess. Most likely though, it'll be in the httpd.conf file, since it's usually a universal solution, and shouldn't have to be checked at every connection.

              SO, if there was an issue wondering about how .php files and .mvc files can work together, it's a non-issue, since apache is working like a "reverse proxy", passing off the .mvc requests to empressa, and getting the results from there. They listen to the same port, and can therefore sit on the same domain and socket.

              And, Miva Merchant deserves a very big "Thank you!!" for that, since it makes our lives (and theirs) much easier.

              Also, in case anyone gets adventurous and wants to work with XMPP (Jabber protocol, or a fancy way of instant messaging), you'll find yourself having to do some workaround in order to get everything up to snuff. I think a lot of the typical solutions will result in iframes, as those will give you some more flexibility.
              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


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

                titus: Thanks for the reply. Glad to have additional information about AJAX as it is all new to me in the past couple of months.
                Glad to know that I'm not yet in the position of knowing just enough to be dangerous :)
                Larry
                Last edited by wajake41; 03-15-13, 03:58 PM.
                Larry
                Luce Kanun Web Design
                www.facebook.com/wajake41
                www.plus.google.com/116415026668025242914/posts?hl=en


                Comment


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

                  Titus: When you say: "JavaScript and browsers have something called the "Same-Origin Policy", which means, any request to a site which isn't of the same origin is stopped immediately." Does this mean that another site attempting to use my PHP program via AJAX will be blocked by the server?
                  Larry
                  Larry
                  Luce Kanun Web Design
                  www.facebook.com/wajake41
                  www.plus.google.com/116415026668025242914/posts?hl=en


                  Comment


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

                    They'll actually be blocked by the browser.

                    But yes, that's accurate.
                    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


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

                      Thanks for the clarification.
                      Larry
                      Larry
                      Luce Kanun Web Design
                      www.facebook.com/wajake41
                      www.plus.google.com/116415026668025242914/posts?hl=en


                      Comment


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

                        Quick question (just curiosity). Why no one is using jQuery (or other framework) ? Is there a limitation inside Miva Merchant?

                        Thank you
                        Emma
                        Zen Radio : Relax :) : www.zenradio.fm
                        MivaScript Tutorials & Scripts : www.mivascript.org

                        Comment


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

                          Originally posted by Emma View Post
                          Quick question (just curiosity). Why no one is using jQuery (or other framework) ? Is there a limitation inside Miva Merchant?

                          Thank you
                          Emma
                          There's no limitation with jQuery. I think it was an initial barebones question without a library. There are a few places in the thread where it talks about jQuery, and I posted an AJAX queue inside here.

                          I use jQuery, since it's ubiquitous. But if I'm on a site where I just need a simple method for calling the server, then I won't pull in a whole library to do the job of one function.
                          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


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

                            I've used jQuery for some other projects; it's a great tool. I may end up using it for this job as well, as it grows in complexity. I did look at the documentation on the jQuery ajax() function, and it didn't look any easier than the straight JS for this task.
                            Last edited by Kent Multer; 03-18-13, 12:34 PM.
                            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

                            Working...
                            X