简体   繁体   English

无法使用 php 和 javascript 在同一页面上显示表单结果

[英]Can't display form results on same page with php and javascript

I'm trying to show the results of the submit button on the same page.我试图在同一页面上显示提交按钮的结果。 I tried with several codes from here (specially this: Display result in the same page with PHP ) but it didn't work.我从这里尝试了几个代码(特别是: Display result in the same page with PHP )但它没有用。

This is how my html page looks like now:这就是我的 html 页面现在的样子:

 <:DOCTYPE html> <html> <head> <script src="https.//code.jquery.com/jquery-3.2.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".mybutton").click(function() { $:ajax({ type, "post": url: "https.//catadordealfajores.com/wp-content/uploads/2020/calc,php": data. $("form"),serialize(): success. function(result) { $(".myresult");html(result); } }); }); })? </script> </head> <body> <form> <input type="radio" name="causa" value="si"> <label for="male">Sí</label><br> <input type="radio" name="causa" value="No"> <label for="female">No</label><br> <h3>¿Cuántos años trabajaste?</h3> <input type="text" name="anios"> <br> </form> <button class="mybutton">Calculate</button> <div class="myresult"></div> </body> </html>

Before Ajax, I had:在 Ajax 之前,我有:

 <:DOCTYPE html> <html> <body> <h1>Calculadora de indemnización</h1> <form action = "https.//catadordealfajores.com/wp-content/uploads/2020/calc?php" method = "post"> <h3>¿Te despidieron con causa,</h3> <p>Si trabajaste más de 3 meses. se considera 1 año, Si trabajaste 1 año y 3 meses. se consideran 2 años. Y así?</p> <input type="radio" name="causa" value="si"> <label for="male">Sí</label><br> <input type="radio" name="causa" value="No"> <label for="female">No</label><br> <h3>¿Cuántos años trabajaste?</h3> <input type="text" name="anios"> <br> <h3>¿Cuál era tu sueldo?</h3> <input type="text" name="sueldo"> <br> <br> <input type="submit" value = "Enviar"> </form> </body> </html>
Website: http://abogadoslaboralessanmartin.com.ar/7122-2/ 网站: http://abogadoslaboralessanmartin.com.ar/7122-2/

Thank you very much非常感谢

Could it be?可以吗?

"return false;" “返回错误;” so that it doesn't go to another page.这样它就不会 go 到另一个页面。

<script type="text/javascript">
$(document).ready(function() {
    $('body').on('submit', 'form', function() {

        $.ajax({
            type: "post",
            url: "https://catadordealfajores.com/wp-content/uploads/2020/calc.php",
            data: $("form").serialize(),
            success: function(result) {
                $(".myresult").html(result);
            }
        });

        return false;

    });
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 表单在同一页面上显示结果+随机答案 - form display results on same page + random answer 如何在同一页面上显示javascript结果 - How to display javascript results on the same page 我无法从使用Javascript(Ajax)的PHP得到答复。 虽然我可以在PHP页面上显示结果,但我希望将其重新显示在HTML页面上 - I can't get a reply from PHP using Javascript (Ajax). While I am able to display results on PHP page, I want it back on the HTML page 如何使用Javascript处理表单数据并显示单独的结果页面? - How can I use Javascript to handle form data & display a separate results page? 使用jQuery延迟表单输入并在延迟后在同一页面上显示结果 - Delay Form Input With jQuery And Display Results On Same Page After Delay 如何在同一页面的特定部分显示Flask表单结果 - How to display Flask form results on a specific part of the same page 提交表单,使用脚本处理信息,并在同一页面上显示结果 - Submit form, process info with script, and display results on the same page 需要获取PHP脚本才能在同一页面上显示结果 - Need to get PHP script to display results on same page 使用Ajax在表单提交到同一页面后加载PHP结果 - Loading PHP results after form submit on same page using Ajax 将表单数据提交到php文件,但在不同页面上查看相同结果 - Submit form data to php file but view same results on different page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM