2017-01-21 15:03
浏览 22


When the submit button is clicked on page1.php the response is printed as HTML format for a moment but it gets automatically deleted.

I want to display the response of page2.php in page1 in the id="output" element.

What am I doing wrong?

Here is the content of page1.php

<script type="text/javascript">
    function func(tosearch) {

            type: 'post',
            url: 'page2.php',
            data: {
                'tosearch' : tosearch
            success: function(result) {

    function print(result) {

<form method="post" action="page1.php">
    <input type="text" name="search" placeholder="Search.."><br><br>
    <input type="submit" name="submit" onclick="func()">
<p id="output">table here!!</p>

Content of page2.php

<?php echo "<table align='center'>"
    ."<td>"."Mr XYZ"."</td>"
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drasv0904 2017-01-21 15:06

    The response isn't being deleted, the page is refreshing. Since you don't want the page to refresh at all, you don't really need that form element. Just remove the form and make the input a plain button to keep the markup simple:

        // your JavaScript
    <input type="text" name="search" placeholder="Search.."><br><br>
    <button onclick="func()">    
    <p id="output">table here!!</p>
    点赞 评论

相关推荐 更多相似问题