Announcement

Collapse
No announcement yet.

passing javascript variables from one application to another

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

  • passing javascript variables from one application to another

    Hello everybody, I have a very basic problem that should be easy to solve but somehow it doesn't...

    1. I have a blank application (A) with javascript content, e.g. the variable "selected_id" with a certain value depending on user interaction (not database-related)
    2. After the user interacts, I want to pass that variable to another blank application (B).
    3. This variable should be processable for a sql statement to search for the certain id in another database table.

    I already tried
    - ajax request
    - building a global php-variable
    - get/post-methods
    - sc_redirect- macro
    - result-loader
    - php-statements in div-container
    - converting js-variable to php-variable

    But nothing led to the assumed result. Can anybody tell me which is the easiest/best way to get a proper solution?
    Many thanks in advance,
    Arne

  • #2
    use sc_redir with one or more parameters (you can create a cookie too and use that when it is on the same domain, but then do check for the existance of the cookie).
    See http://www.scriptcase.net/docs/en_us...iptcase-macros in the manual under sc-redir. It could hardly be easier.

    Comment


    • #3
      Thanks a lot, for me it also seemed to be the fastest and easiest way and I tried it already. But three problems remain:

      1. How can I implement the php code with sc_redir only within the JS-event? (event triggers when User clicks on a open layers map). I can do it only globally
      2. What is the syntax of sc_redir for passing a JS-Variable? I only sent php variables or strings successfully
      3. How can I avoid using a new target? I am using a dashboard where A and B are already open and next to each other. So I do not need a modal, self or blank target that opens.

      Should be easy to solve but the documentation about macros does not help for these questions.

      Can anyone help me?
      thanks!
      Last edited by Arne; 11-05-2015, 07:24 AM.

      Comment


      • #4
        Or more generally, is there a possibility to interact between blank applications, avoiding that these apps already completed their php code?

        Comment


        • #5
          1: I dont get your first question. Do you have a button somewhere on your form? If not then go for a php code button...
          2: sc_redir is a scriptcase macro. If you have a JS variable then you can not pass it UNLESS you could use JQuery to set a variable (needs fiddling but can be done). I dont fully get what you want to do... Click on some openlayermap and jump to your application? You can always redirect using javascript see here: http://www.tizag.com/javascriptT/javascriptredirect.php
          But you would need to add javascript code to your blank application. You can always redirect to www.mysite.com?redir=myparameters
          3: windows.location is not opening a new window afaik

          Comment


          • #6
            Thanks for your hints, basically I want to do the following:
            - App A is a blank application with an OpenLayers Map.
            - When the user clicks on the map (OpenLayers Event), a javascript-Variable is stored with the id for the specific area that was clicked.
            - Now I want to send this "Information"/area-ID (I do not mind if with ajax, redirect or something completely different, using php variable or js) to another blank application (B).
            - This App B should be able to process the variable for another database request (e.g. search for population of the requested area-ID)

            Maybe now things clearified a bit?

            Comment


            • #7
              Aha clear. This is how I would do it. Since you already have that variable, lets call it var_redir and lets assume it has a value 12345 and it runs on myblankapp1.
              I can do a window.location="http://mysite.com/myblankapp2?redir="+var_redir in javascript. Since you already can store the variable you should be able to add that line after you filled the javascript variable.
              Hence in myblankapp2 you can use php with $_GET (see here: http://php.net/manual/en/reserved.variables.get.php)
              So I would put some php code:
              $myparam=$_GET["redir"];
              then the rest of my code.. Do add checks to see if the variable is filled (parameter is truly give).
              That should help you I think.

              Comment


              • #8
                Perfect! That works, many thanks!!
                I've tried something similar already but the get-Method was probably missing.

                Since I am using a Dashboard with two widgets (App A is embedded in widget 2 and App B is embedded in widget 1) I used the following redirect:

                parent.document.getElementById('id-iframe-widget1').src="../myblankapp2?redir="+var_redir

                so again, thanks a lot!

                Comment

                Working...
                X