from javascript to php to javascript -need correction -
im making , code isnt working
<script src='jq.js'></script> <script> function geturlparameter(name) { return decodeuri( (regexp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] ); } nick = geturlparameter('kagnick') </script> <?php $url = "https://api.kag2d.com/player/"+nick+"/status"; $curl = curl_init($url); curl_setopt($curl, curlopt_returntransfer, 1); $result = curl_exec($curl); curl_close($curl); ?> <script> status = $result.split("\n") if(status[4].indexof("true,") != -1) document.write("gold player") </script>
what wrong code? i´m trying do: -mazeygg.com/penis?kagnick=mazey return ´gold player´ in first js/jq part: make /penis.html*?kagnick=nickname* (nickname = mazey, example) in second part, php: connect website in third part, js again: split website , print (check http://api.kag2d.com/player/mazey/status)
i chose because did not find proper way php part in js (i code js, not php), if know how: it´s appreciated! if not: me fixing code can move on.
thanks, in advance
"bridge" php js:
<script type="application/javascript" language="javascript"> var somevariablethatyouwanttogetfromphp="<?=$phpvariable?>"; </script>
when php has executed, there such output html:
<script type="text/javascript" language="javascript"> var somevariablethatyouwanttogetfromphp="wheeha! js has got value of php variable"; //and here later able use </script>
"bridge" js php little bit more complex. can't some js variable , put in some php script @ some time. have make http request server php.
forms do. if have form in html code:
<form name="form1" action="phpscript.php" method="post"> <input name="passingjsvartophp" type="hidden" value="" /> </form>
, may later submit form js code , way pass variable want php script. js code:
document.form1.passingjsvartophp.value=yourjsvariablethatyouwanttoputinyourphpscript; document.form1.submit();
and there php code on server side, catch variable:
<?php $yeahgotthejsvariable=$_post['passingjsvartophp']; //and here may use variable passed js code ?>
you have understand, when form submit()s, phpscript.php loaded instead of page form.
you have understand synchronous request-response model of http before writing such web applications, , before this, wait bit javascript. level 1.
p. s. level 2: ajax.
p. p. s. level 3: websockets.
Comments
Post a Comment