Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 弹出消息和ajax到jquery表单_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 弹出消息和ajax到jquery表单

Javascript 弹出消息和ajax到jquery表单,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我用PHP和jQuery创建了一个表单,我在我的网站的页脚中添加了这个表单,我所需要的是在我的网站的主窗口中而不是页脚中显示表单结果,并使其在不刷新页面的情况下工作(使用ajax)。我在这里添加了我的全部代码: <form enctype="multipart/form-data" action="" method="post"> <input name="url" type="text"/> <input type="submit" name="su

我用PHP和jQuery创建了一个表单,我在我的网站的页脚中添加了这个表单,我所需要的是在我的网站的主窗口中而不是页脚中显示表单结果,并使其在不刷新页面的情况下工作(使用ajax)。我在这里添加了我的全部代码:

<form enctype="multipart/form-data" action="" method="post">
   <input name="url" type="text"/>
    <input type="submit" name="submit" value="Check" class="btn btn-primary"/><br/>
</form>

<?php
if(isset($_REQUEST['submit'])) {
    $url = $_REQUEST['url'];
if(substr( $string_n, 0, 7 ) != "http://" && substr( $string_n, 0, 8 ) != "https://")
$url = "http://".$url;
if(stripos($url,"folder/")>0)
$content = file_get_contents($url);
else
$content = file_get_contents($url."/folder/");
if(preg_match("/Copyright ver\. ([0-9.]+)/", $content, $result))
echo "Your year is : ".$result[1];
else
echo "Sorry cannot determine year";
}
?>


编辑

别忘了把jquery放在html页面的顶部

检查下面的解决方案

//这将是您的html文件

<form id="form1" enctype="multipart/form-data" action="" method="post">
    <input name="url" type="text"/>
    <input type="submit" name="submit" value="Check" class="btn btn-primary"/><br/>
</form>
<script>

    $(function() {
    $('#form1').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
        type: 'post',
        url: 'post.php',
        data: $('form').serialize(),
        success: function(html) {
            alert(html);
        }
        });
    });
    });
</script>

如果您只使用提供的代码,那么仍然缺少一些AJAX代码。由于您同时使用了jQuery和JavaScript标记,我不确定您使用的是香草还是jQuery(我的示例使用jQuery)

我的示例将在用户单击submit按钮时发出AJAX请求
$your_url
需要设置为包含问题中指定的PHP代码的文件

$('my#u按钮')。在('click',函数(e){
e、 预防默认值();
$.ajax({
类型:“POST”,
数据:{
text:$('#某些#text').val(),
},
url:“”,
成功:功能(数据){
console.log($data);
}
});
});


不存在,必须创建,但我不知道如何创建,当我按下检查按钮时,页面会刷新,我看到了,但如果我没有任何post.php文件?ajax会是什么样子?其他方式不存在吗?我的意思是没有这个php文件?我想你不清楚
ajax
。。您正在从该表单发布
url
,好吗??用你的php代码对这个url做些什么??所以,如果你使用ajax发布url,你就必须把php代码放在某个地方?你明白我想说的吗?你能帮我做这个代码吗?因为我做不到。汤米,谢谢你的回答,你能帮我做整个代码吗?是的,你插入了
jquery
如果没有,那么就放jquery???如果是,则输入
回波“测试”并检查它是否发出警报
test
。。。然后你会知道你能举个例子吗?如何回应“测试”;?我使用jquery。谢谢你能帮我做一下回音吗?我认为你的代码是工作,但没有显示任何东西对不起,我没有;我不明白?如何显示$result[1]?@RobertD您应该从一些php和jquery基础知识开始。。这样不行的。。。
<?php
if (isset($_REQUEST['submit']))
{
    $url = $_REQUEST['url'];
    if (substr($string_n, 0, 7) != "http://" && substr($string_n, 0, 8) != "https://")
        $url = "http://" . $url;
    if (stripos($url, "folder/") > 0)
        $content = file_get_contents($url);
    else
        $content = file_get_contents($url . "/folder/");
    if (preg_match("/Copyright ver\. ([0-9.]+)/", $content, $result))
        echo "Your year is : " . $result[1];
    else
        echo "Sorry cannot determine year";
}
?>