使用JS以HTML格式显示PHP输出

使用JS以HTML格式显示PHP输出

问题描述:

So currently I am working on a simple login authentication. I have an HTML page and PHP script using cURL to authenticate against a website. What I want to do is, instead of after user input pressing submit and switching to the PHP page for the "correct" "Incorrect" echo, I want JS to just give a small message under the submit button giving that message so they can enter info again.

Thank you it was fixed and working now thank you shyju

所以目前我正在进行简单的登录验证。 我有一个HTML页面和PHP脚本使用cURL来验证网站。 我想要做的是,而不是在用户输入后按提交并切换到PHP页面以获得“正确”的“不正确”回声,我希望JS只在提交按钮下给出一条小消息,提供该消息,以便他们可以输入 再次信息。 p>

谢谢你它已修复并正在工作谢谢shyju p> div>

You may need to stop the default behavior for the button submit(posting the form the the page without ajax). Try jQuery preventDefault method.

$(function(){
  $("#sub").click(function(e){
     e.preventDefault();

     //now post the form using ajax to the server page for validation
      $.post($("#login").attr("action"), $("#login :input").serializeArray(),
                                                                  function(info){
          $("#result").html(info);
          clearInput();
      });

  });
});

You should do the call using AJAX instead of submitting the form.

In your case, you might want to use jQuery's post.