Dzint Posted July 28, 2008 Report Share Posted July 28, 2008 Kā lai php masīvu dabū uz Java Script .js faila funkciju ir php kods $aDats = Array(); $aDats[0] = "56.71"; $aDats[1] = "58.81"; $aDats[2] = "56.51"; $aDats[3] = "53.56"; $aDats[4] = "56.61"; echo "<script src='../scripti/kautkas.js' type='text/javascript'></script>"; echo "<script> setJavaScriptArray ($vertiba, $aDats); </script> "; un JavaScript js fails ar funkciju function setJavaScriptArray (dats1, phpmasivs){ var JavaScriptMasivs = new Array(); JavaScriptMasivs = [color="#FF0000"]// Šeit vajadzētu to php masīvu($aDats) dabūt[/color] } Link to comment Share on other sites More sharing options...
andrisp Posted July 28, 2008 Report Share Posted July 28, 2008 Pārsauc to .js failu par .php, un tad ar PHP palīdzību ģenerē to JS masīvu (tāpat kā tu ģenerētu HTML). Link to comment Share on other sites More sharing options...
Dzint Posted July 28, 2008 Author Report Share Posted July 28, 2008 Pārsauc to .js failu par .php, un tad ar PHP palīdzību ģenerē to JS masīvu (tāpat kā tu ģenerētu HTML). Man tai js failā ir vairākas JavaScript funkcijas Link to comment Share on other sites More sharing options...
andrisp Posted July 28, 2008 Report Share Posted July 28, 2008 (edited) Tas nekas. Pārlūkam vienalga kāds paplašinājums ir js failam. Vienīgi atceries, ka pārlūkiem patīk kešot Javascript failus. Lai tas nenotiktu, jānodrošina, ka URL uz JS vienmēr ir mainīgs. Viens vienkārš variants ir piekabināt dummy parametru, kas visu laiku mainās: links_uz_js.php?t=<?php echo time(); ?> Tāpat arī iesaku tad statisko JS daļu izdalīt atsevišķā JS failā, ko pārlūks tad arī varēs kešot. Edited July 28, 2008 by andrisp Link to comment Share on other sites More sharing options...
codez Posted July 28, 2008 Report Share Posted July 28, 2008 (edited) echo "<script> setJavaScriptArray ($vertiba, ".json_encode($aDats).");</script> "; Edited July 28, 2008 by codez Link to comment Share on other sites More sharing options...
Dzint Posted July 28, 2008 Author Report Share Posted July 28, 2008 Paldies, skaidrs Link to comment Share on other sites More sharing options...
bubu Posted July 28, 2008 Report Share Posted July 28, 2008 codez: un kur izrakt maģisku setJavaScriptArray funkciju? Link to comment Share on other sites More sharing options...
Dzint Posted July 28, 2008 Author Report Share Posted July 28, 2008 codez: un kur izrakt maģisku setJavaScriptArray funkciju? Tā ir lietotāja definēta funkcija Link to comment Share on other sites More sharing options...
Dzint Posted July 28, 2008 Author Report Share Posted July 28, 2008 (edited) echo "<script> setJavaScriptArray ($vertiba, ".json_encode($aDats).");</script> "; Paldies,šis variants šai gadijumā noderēja labāk. Edited July 28, 2008 by Dzint Link to comment Share on other sites More sharing options...
Recommended Posts