ajax?

djcustom

New Member
Messages
17
Reaction score
0
Points
0
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.
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
I may have misunderstood you, but are you looking for a way to use data from a mySQL database to populate the JS arrays?
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
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:
<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:

lordskid

New Member
Messages
41
Reaction score
0
Points
0
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:
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.
 
Top