jQuery的不是调用PHP不是、jQuery、PHP

2023-09-11 01:22:21 作者:亿人不及你一人

由于某些原因,jQuery是不加载我的PHP文件。点击该按钮和页面只是刷新。我已经验证了jQuery是工作和点击功能的工作,以及。一旦它到达 $。发布它似乎并没有调用该文件,并通过暂停和呼应的结果。该目录是正确的PHP文件。我很茫然。任何想法?

  // HTML code
<输入ID =DOIT级=中的蓝色按钮类型=提交名称=DOIT值=登录>

// jQuery的code:
$('#DOIT)。点击(函数(){
    $('#全屏)显示()。
    .post的$('./删除 - 杂项/测试ajax- code.php',功能(数据){
         $('#全屏')隐藏()。
         警报(数据);
    })
});

// PHP的code(测试ajax- code.php)
< PHP
    睡眠(10);
    回声完成;
?>
 

解决方案

尝试从URL的开头删除点。

  $。员额('/删除-杂项/测试ajax- code.php',...
 

我不能给你如​​何在URL路径点的工作原理完全由于经验不足,详细的解释,但我会做出这样的社区维基,以便让别人解释。

编辑:我问一个关于这个话题的问题,答案是伟大的:What在URL中做了点呢?

jquery 用ajax 只能向php输入信息但是获取不到json

For some reason, jQuery isn't loading my php file. The button is clicked and the page just refreshes. I have verified jQuery is working and the click function is working as well. Once it gets to $.post it doesn't seem to call that file and go through the pause and echo the result. The directory is correct for the php file. I am at a loss. Any ideas?

// HTML Code    
<input id="doit" class="medium blue button" type="submit" name="doit" value="Sign in">

//jQuery code:
$('#doit').click(function(){
    $('#fullscreen').show();
    $.post('./delete-misc/test-ajax-code.php', function(data){
         $('#fullscreen').hide();
         alert(data);
    })
});

// Php code (test-ajax-code.php)
<?php
    sleep(10);
    echo "Done";
?>

解决方案

Try to remove the dot from the beginning of the URL.

$.post('/delete-misc/test-ajax-code.php', ...

I cannot give you a detailed explanation on how a dot in the URL path works exactly due to lack of experience, but I will make this a community wiki in order to let someone explain it.

EDIT: I asked a question about this topic, the answers are great: What does a dot mean in a URL?