+ Reply to Thread
Results 1 to 5 of 5

Thread: ajax?

  1. #1
    djcustom is offline x10Hosting Member djcustom is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    15

    ajax?

    I have the following 2 arrays in a Javascript i use

    var coupons = new Array (
    "abc",
    "def",
    "ghi"
    );

    var coupdc = new Array (
    20,
    21,
    25
    );

    I no longer want the data visible. I also have a database that contains the fields with this data. Is there a way i can load the data into the array. If there is a reasonable way can someone help with an example.

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: ajax?

    I may have misunderstood you, but are you looking for a way to use data from a mySQL database to populate the JS arrays?

  3. #3
    djcustom is offline x10Hosting Member djcustom is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    15

    Re: ajax?

    That is exactly what im trying to do.

  4. #4
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: ajax?

    OK, is your javascript embeded into the page <script>javascript code here</script> or <script scr="javascript.js"></script>? If it's the first, you can just add PHP code into that to get the contents and make the array that way.

    an example of that would be

    PHP Code:
    <script type="text/javascript">

    <?php
    $num 
    0;
    $result mysql_query("SELECT name, discount FROM coupons");
    while (
    $result mysql_fetch_assoc($result))
    {
      if (
    $num != 0)
      {
        
    $coupon_name .= ',';
        
    $coupon_value .= ',';
      }
      
    $coupon_name .= "\"".$result['name']."\"";
      
    $coupon_value .= $result['discount'];
    }
    ?>

    var coupons = array(<?php echo $coupon_name ?>);
    var coupdc = array(<?php echo $coupon_value ?>);

    </script>
    Last edited by xPlozion; 02-18-2009 at 07:44 PM.

  5. #5
    lordskid is offline x10Hosting Member lordskid is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    41

    Post Re: ajax?

    I believe you what you want is ajax. and the javascript command xmlHttpRequest.

    Unfortunately I don't know much about AJAX and is still trying to research on it for now. I will post back in this page if I find an easy to understand answer.

    for now I use an obfuscation technique.

    so for your code it would be something like this:


    by having my php generate "\xNN" strings instead of the normal characters.
    PHP Code:
    var coupons = new Array (
         
    "\x61\x62\x63",
         
    "\x64\x65\x66",
         
    "\x67\x68\x69"
    );

    var 
    coupdc = new Array (
        
    20,
        
    21,
        
    25
    ); 
    that is if what you want is for people not to see your code.

+ Reply to Thread

Similar Threads

  1. AJAX games...
    By Sup3rkirby in forum Off Topic
    Replies: 1
    Last Post: 09-11-2008, 06:29 PM
  2. AJAX response xml not working
    By jspcodes in forum Programming Help
    Replies: 3
    Last Post: 06-05-2008, 08:12 AM
  3. AJAX Gaming Server?
    By Sup3rkirby in forum Programming Help
    Replies: 14
    Last Post: 12-26-2007, 04:14 PM
  4. Using AJAX to Spy On You
    By subvertman in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 08-15-2005, 08:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers