Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用AJAX提交表单,并根据表单中的数据跳转到特定页面_Jquery_Ajax_Forms - Fatal编程技术网

Jquery 使用AJAX提交表单,并根据表单中的数据跳转到特定页面

Jquery 使用AJAX提交表单,并根据表单中的数据跳转到特定页面,jquery,ajax,forms,Jquery,Ajax,Forms,我有一个表格,里面有一个搜索框。根据用户搜索的内容,我跳转到特定页面。使用$.ajax,如何跳转到该url并相应地将数据发送到该url HTML: JS //当用户按enter键提交表单时,跳转到url $(“#搜索”).keyup(函数(事件){ 如果(event.keyCode==13){ 表单提交(); } var landingUrl='/page/subpage/';//页面根据用户搜索的内容而变化,因此我无法放置 var数据='…'; $.ajax({ 类型:“POST”, 数据

我有一个表格,里面有一个搜索框。根据用户搜索的内容,我跳转到特定页面。使用$.ajax,如何跳转到该url并相应地将数据发送到该url

HTML:


JS

//当用户按enter键提交表单时,跳转到url
$(“#搜索”).keyup(函数(事件){
如果(event.keyCode==13){
表单提交();
}
var landingUrl='/page/subpage/';//页面根据用户搜索的内容而变化,因此我无法放置
var数据='…';
$.ajax({
类型:“POST”,
数据:{
数据
},
网址:(landingUrl),
contentType:“application/x-www-form-urlencoded”,
成功:函数(){
console.log(“发送后数据”);
},
错误:函数(){
$window.open(landingUrl,“_self”);
}
});
表单提交();
});

如果您需要更多信息,请随时询问。

使用window.location实例open@Vijay我在哪里用这个?我想你应该修改你的问题。我想你问的是:“如何在不使用AJAX刷新页面的情况下显示搜索结果?”@user3275665我想我把它复杂化了。我只想发送一个POST请求并跳转到一个特定的url。当我到达那个页面时,我想得到那个帖子的数据
<form method = "POST">
<input id = "search"...>
</form>
//When user presses enter submit the form, jump to the url


$("#search").keyup(function(event){
    if(event.keyCode == 13){
        form.submit();
    }

            var landingUrl = '/page/subpage/'; //page changes depending on what the user searched for so I can't put <form action = "/page/subpage/">
            var data = '...';

            $.ajax({
              type: "POST",
              data: {
                  data
              },
              url: (landingUrl),
              contentType: "application/x-www-form-urlencoded",
              success: function() {
                  console.log("post data sent");
              },
              error: function() {
                  $window.open(landingUrl, "_self");
              }
          });
         form.submit();
    });