將php的變數在html中傳給ajax進行賦值
阿新 • • 發佈:2018-12-10
這裡是我自己剛學習用的一種間接的方法,思路是利用一個input標籤把php放進去,然後通過呼叫這個input標籤的id來實現把值傳遞給ajax,以方便下一步在其他php檔案中使用。僅供參考。
html程式碼如下:
<!--head呼叫ajax--> <script type="text/javascript" src="https://code.jquery.com/jquery-3.0.0.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#ggym").click(function(){ var ndyming = $("#ndym").val(); $.post('ggym.php',{oid:oiding},function(data){ alert(data); }) }) }) </script>
然後:
<tr> <td width="15%" align="right" valign="top">訂單號:</td> <td><input type="text" id="oiding" readonly=true value="<?php echo $oid; ?>"></td> </tr>
如果想要看不出來,可以把input標籤設定成hide。