Passing PHP Array to Javascript OnLoad -


i trying pass in php array javascript function through onload();

in similardomains.php:

<?php $domainsjs = json_encode($similardomainsunique); ?> <body onload="init(<?php echo "\"$domainsjs\""; ?>);"> 

i pass string object in order later process string using json.parse(). in javascript have

var obj =  json.parse(domainsjs); 

for string processing. seems have syntaxerror: syntax error @ line 1. html doctype. if remove doctype, goes next first line. appears when have body onload calling php did.

how can process php array in order used in javascript. after said , done, have input processed values js array.

here body onload turns out in html

<body onload="init("{"0":"estatelawyer.com","1":"reaestatelawyer.com","2":"estately.com","3":"thestate.com","4":"estaterescue.com","5":"boisestate.edu","10":"99acres.com","11":"1point3acres.com","14":"green-acres.com","22":"backcountry.com","24":"baby-kingdom.com","25":"landattorney.com","27":"siteground.com","28":"247realmedia.com","30":"siteground.biz","31":"arealme.com","32":"farming-simulator.com","33":"amkingdom.com","34":"searchengineland.com","35":"shoretelsky.com","36":"grantland.com","38":"amsoil.com","40":"lostrealm.ca","41":"kingdomofloathing.com","42":"shorewest.com","44":"domaintools.com","45":"domain.com.au","46":"realmadridstream.net","47":"farming2015mods.com","48":"travelandleisure.com","49":"landofnod.com","51":"bringmesports.com","52":"cricketcountry.com","53":"bringthebaconhome.com\/user\/dashboard","54":"ollando.com","55":"domain.com","57":"travelandlearntrips.com","58":"scarffruit.country","59":"78land.com","92":"propertylawyer.com","93":"propertylawyergroup.com","94":"propertyattorney.com","95":"rocketlawyer.com"}");"> 

you should need echo straight without quotes because it's json object

<body onload="init(<?php echo $domainsjs ?>);"> 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -