www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript, PHP question.

  1. #1
    Join Date
    Nov 2008
    Posts
    11

    Javascript, PHP question.

    I am designing a web application that runs in Javascript, modified a bit to enable object-oriented programming. As of now, all of the objects are being loaded from XML files, but the files are becoming unwieldy and large. I have a PHP-MySQL back end that I could use, and I was thinking about using that to store the object data.

    My back-end experience is not tremendous, and the only way I can think of for the PHP to load data into Javascript is to have it (on the server-side) literally write the Javascript code or XML files and then have the front-end read it normally. Does anyone know a more elegant way to have PHP interact with Javascript?

    Thanks in advance!

  2. #2
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    AJAX...
    or embed PHP in your javascript to reduce redundant calls
    or put the javascript in your PHP so that you only call the javascript when actually needed

    an example of what you are trying to do would help
    ...but stupidity is terminal.

  3. #3
    Join Date
    Nov 2008
    Posts
    11
    I'll try to illustrate.

    I create a class widget in Javascript:
    function Widget(attributes){
    this.property1 = "a";
    this.property2 = "b";
    //etc.
    }

    The various widgets that the app creates are all of the same class and thus share the same properties, functions, etc. Individual widgets may have different values for their properties, based on the attributes passed to the constructor function by the XML. This is resulting in a very unwieldy and complex XML file, which is why I'm considering storing the data in a mySQL database. Can use PHP to write directly to the Javascript in some way other than just echoing javacript code? I don't think AJAX will be of much help, since the objects in question will generally be created when the app first loads, rather than dynamically as the app runs.

  4. #4
    Join Date
    Sep 2008
    Location
    Mexico
    Posts
    786
    something like...

    function Widget(attributes){
    this.property1 = "<?php include ("property1.php"); ?>";
    this.property2 = "<?php include ("property2.php"); ?>";
    //etc.
    }
    ... where propertyX.php is processed before the page is loaded based on whatever parameters are needed for said widget and returns the required value?

    OR...
    function Widget(attributes){
    <?php include ("WidgetProperty.php"); ?>
    }

    ... where WidgetProperty.php is processed before the page is loaded based on whatever parameters are needed for said widget and returns the required ....
    this.property1 = "a";
    this.property2 = "b";
    //etc.



    ....this would be an example of embedded php
    Last edited by opifex; 09-12-2009 at 03:54 PM. Reason: uh... and can't spell!
    ...but stupidity is terminal.

  5. #5
    Join Date
    Nov 2008
    Posts
    11
    I might try that. Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles