AJAX url - 在测试服务器上打开相对路径

时间:2015-09-03 14:33:06

标签: jquery ajax localhost

我想将ajax请求的url设置为指向

  

http://local.website/page/childpage或local.website/page/childpage

其中local是localhost。 (我修改了主机文件以将localhost更改为本地)

$landingUrl = /page/childpage;

 $.ajax({
           type: "POST",
           data: data
           url: (landingUrl),
           success: function () {
              console.log("post data sent");
           },
           error: function () {
              $window.open(landingUrl, "_self");
           }
          });

问题是,如果没有表单

,当前的实现不会跳转到成功的URL

1 个答案:

答案 0 :(得分:0)

工作代码:

var landingUrl = "/page/childpage"; // forgot ""
var data = "your data"; // 'data' was not definied

$.ajax({
           type: "POST",
           data: data, // forgot ,
           url: (landingUrl),
           success: function () {
              console.log("post data sent");
           },
           error: function () {
              window.open(landingUrl, "_self");
           }
});