如何使用ajax调用php并返回结果
how to use ajax to call a php and return a result
我在php中有一段代码,onclick I将在其中调用javascript。但我不知道如何使用ajax并将值传递给php并返回
<script>
function getURL(e)
{
//ajax code that will check.php
}
</script>
body:main.php(当前页面)。它将提醒正确。
<?php $url = "www.google.com"; ?>
<a href="#" onclick="getURL('<?php echo $url; ?>');">click me</a>
ajax将调用的php。。check.php
<?php
$html = file_get_html($url);
foreach($html->find('iframe') as $e)
echo $e->src;
return "correct" //idk if it's correct to return. should it be echo? ?>
我需要返回结果。
可以要求一些示例的基本代码来调用ajax到php吗?它会提醒"正确"的单词。或者php将返回的任何内容。谢谢:)
May a ask for some sample basic code to call of ajax to php using this?
and it will alert the "correct" word. or anything that the php will return
我认为您不应该将ajax用于这种警报:
HTML:
<a href="#" onclick="getUrl('www.google.com');">click me</a>
<div id="result"></div>
JavaScript代码:
function getUrl( url ){
var result = document.getElementById('result');
// Just a Simple validation
var regex = /www'.google'.com/;
if( regex.test(url) ){
result.innerHTML = "Correct";
}
else{
result.innerHTML = "Error";
}
}
演示:
查看此处的工作示例:http://jsfiddle.net/jogesh_pi/6UGFT/
类似于:
<script>
function getURL(e){
//ajax code that will check.php
$.get('check.php',function(data){
alert(data);
});
}
</script>
相关文章:
- JSONP请求返回结果,但也触发error_callback
- async问题,JS Promise无法返回结果,但可以使用console.log
- Meteor js-控制台显示'未定义'即使返回结果
- 正在等待HTTP调用从函数返回结果
- 使用函数for循环遍历对象以更改值,然后返回结果
- 迭代 JSON 文件并且未在 Javascript 中正确返回结果
- Javascript 函数不返回结果
- 用逗号分隔返回结果中的对象
- 需要呈现MongoDB查询返回结果的特定索引/位置
- HTML5 文件阅读器如何返回结果
- javascript循环遍历列表项,并在数组中返回结果
- 使用jquery UI next按钮提交输入字段值,php将返回结果
- 在angularjs工厂中,如何在函数解析后返回结果
- 我在jQuery中的Rock Paper Scissors程序只在平局时返回结果
- 如何使用ajax调用php并返回结果
- 添加第二维度的Javascript未返回结果
- Node.js没有返回结果
- jquery裁剪图像selction未返回结果
- 如何在phonegap javascript函数中返回结果
- 如果文本筛选器在ng重复中未返回结果,则显示消息