简体   繁体   English

使用jQuery Web在同一页面上显示来自另一个HTML的结果

[英]Display reesults from another html on same page using jquery web

Below is my code of html and jquery, i want to dsiplay results on submit button on the same page rather than its goes on next page. 下面是我的html和jquery代码,我想在同一页面上的提交按钮上显示结果,而不是在下一页上。 But it is not returning me any results and go to next page. 但这并没有返回任何结果,请转到下一页。 HTML code HTML代码

<form id="create" action="/engine_search/search/" method="get">
                            <input style="height:40px;" type="text" class="form-control" placeholder="Search" name="q">
                            <center>
                            <input style="float:left; margin-left:150px;" type="submit" class="btn btn-default" value="Search">
                                </center>
                         </form>

jquery code: jQuery代码:

<script>
$(document).ready(function() {
$('#create').submit(function() { // catch the form's submit event
    $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#created').html(response); // update the DIV
        }
    });
    return false; // cancel original event to prevent form submitting
});
});
</script>

You should use event.preventDefault(); 您应该使用event.preventDefault();

<script>
$(document).ready(function() {
$('#create').submit(function(event) { // catch the form's submit event
    event.preventDefault();
    $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
            $('#created').html(response); // update the DIV
        }
    });
    return false; // cancel original event to prevent form submitting
});
});
</script>

Look for console for any errors. 查找控制台是否有任何错误。 It might be helpful. 这可能会有所帮助。

<input style="float:left; margin-left:150px;" type="submit" class="btn btn-default" value="Search" onclick="return SubmitFunction(this);">

Javascript : Javascript:

function SubmitFunction(thisId){
 $.ajax({ // create an AJAX call...
    data: $(thisId).serialize(), // get the form data
    type: $(thisId).attr('method'), // GET or POST
    url: $(thisId).attr('action'), // the file to call
    success: function(response) { // on success..
        $('#created').html(response); // update the DIV
    }
});

 return false; // cancel original event to prevent form submitting

} }

暂无
暂无

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

相关问题 如何使用html5和jquery在网页中显示pdf内容? - How to display pdf content in web page using html5 and jquery? 如何使用html,javascript / jquery上传图像并将其显示在同一页面中 - How to upload an image and display it in the same page using html, javascript / jquery 使用Google Web应用程序-我可以在同一Web应用程序中将变量从一个HTML页面传递到另一个HTML页面 - Using a Google Web App - Can I pass a variable from one HTML page to another within the same web app 在jQuery TE中获取HTML格式,并在另一个HTML页面的Div中显示相同的格式 - Get the HTML formatting in jQuery TE and display the same formatting in a Div in another HTML Page 使用jQuery从一个HTML页面重定向到另一页面 - Redirect from one html page to another page using jquery 使用 jquery 将整个 html div 从一个页面移动到另一个页面 - move an entire html div from one page to another using jquery 使用jQuery抓取另一个网页的内容 - Grabbing contents from another web page using jQuery 使用jQuery从一个项目中的网页重定向到另一个项目 - Redirect from web page in one project to another project using jquery 如何使用html中的onclick属性从另一个网页调用一个网页的javascript函数? - How to call the javascript function of one web page from another web page using onclick attribute in html? 从网页获取数据,然后在另一个网页上显示 - Get Data from a Web Page, then Display It On Another Web Page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM