2014年6月3日 星期二

Javascript 與 PHP

A.javascript轉頁post呼叫php:

HTML:
 <form action='".$PHP_SELF."' method='post'>
 <input type='hidden' name='filelink' id='filelink' value='say it' >
 <input type='submit' name='parse' value='Parsing' >
</form>
PHP:
  echo("alert('".$_REQUEST["filelink"]."');");
      (一定要加上 ' 符號);

   變數宣告-  echo("var filelink = '".$_REQUEST["filelink"]."';");


B.PHP呼叫帶參數javascript function:
   echo ("<td><input type='button' name='delete' value='delete'            onclick=\"senddelete('".$row['id']."','".$row['link']."')\" > </td>");



C.上傳檔案名稱重複的重新命名:
      $splitname = explode(".", $_FILES['file']['name']);
      $name = $splitname[0];
      $extension = $splitname[1];

      $increment = 1; //start with no suffix
           
      while(file_exists("upload/".$name .'('.$increment . ').' . $extension)) {
         $increment++;
     
      }

      $newfilename = $name .'('.$increment . ').' . $extension;

D.onclick 呼叫 php

  <input id="do" class="button1" type="button" name="bu2"  size="3" onclick="callPHP()" value="getcon2" >


 function callPHP() {
      $.ajax({
           type: "POST",
           url: 'components/com_foxbmi/callurl.php',
           data:{action:'call_this'},
           success:function(html) {
             alert(html);
           }

      });
 }


E.使用PHP做post與get html source:

  <?php
$postdata = http_build_query(
    array(
        'id' => '0123456789',
        'mac' => '112233445566',
        'date' => '2014/10/10 11:11:11',
   
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('http://120.126.40.58:8080/FoxLink/UpLoad/RRUpLoad', false, $context);

     echo $result;
   
     /*
    $url = 'http://120.126.40.58:8080/FoxLink/UpLoad/RRUpLoad';
    echo file_get_contents($url);
    */
   
?>

沒有留言:

張貼留言