我需要關於如何從JavaScript內調用外部PHP腳本的幫助。 在我的例子見下面如何從JavaScript內部調用PHP腳本
的index.php
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var myName = 'John';
phpResult = /* Need help calling script.php passing is myName and assigning result to phpResult */;
document.getElementById("demo").innerHTML = "The text from the intro paragraph is " + phpResult;
</script>
</body>
</html>
的script.php
<?php
//script.php
//Need help adding last name to John (i.e. Smith) and returning John Smith to calling javascript
?>
PHP在服務器上運行。它的工作是使用由瀏覽器運行的HTML/JavaScript生成頁面。當瀏覽器運行JavaScript時,PHP自完成以來就已經很久了。您需要查看AJAX以向服務器發出* new *請求。 –
第二點是,如果你想要添加新的名稱或最後一個名稱,那麼你需要創建一個表格進一步 –
可能重複的[從javascript調用php函數](http://stackoverflow.com/questions/7165395/call- php-function-from-javascript) –