javascript 通过 jQuery/Ajax 调用 PHP 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3680343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call PHP page via jQuery/Ajax
提问by test
Let's say I have a PHP page and inside that PHP page I just have <?php echo "Hello World!"; ?>and I want to use JavaScript (preferabbly jQuery) and AJAX to CALL that php page and return it's output (which would be "Hello World!")
假设我有一个 PHP 页面,在该 PHP 页面中我刚刚拥有<?php echo "Hello World!"; ?>,我想使用 JavaScript(最好是 jQuery)和 AJAX 来调用该 php 页面并返回它的输出(这将是“Hello World!”)
How is this done?
这是怎么做的?
回答by Stephen
Pretty basic.
非常基本。
You'll find lots of examples near the bottom.
你会在底部附近找到很多例子。
回答by Robert
The datawill contain the text from the page, do what you want with it. In this case, set the #responseAreatext to contain it.
在data将包含来自网页中的文字,你想用它的东西。在这种情况下,设置#responseArea文本以包含它。
$.ajax({
url: "yourPage.php",
success: function(data){
$("#responseArea").text(data);
}
});

