为什么url无法连接?

时间:2020-01-03 04:59:02

标签: ajax spring-mvc

Code
$(document).ready(function(){
    $("#btn").click(function(event){
        event.preventDefault();
        alert("AJAX request successfully completed");
        ajaxpost();
      });
      function ajaxpost()
      {
          console.log("formData1");  
          var formdata={
                  name:$("#name").val(),
                inputcutoff:$("#inputcutoffdate").val(),
                releasedate:$("#releaseDate").val(),
                    status:$("#status").val()

          }
          alert("Changed into json format");
          console.log(formdata);
          $.ajax({
              type : "POST",
              contentType : "application/json", 
              url : "/company/addrelease",
              data : JSON.stringify(formdata),
              dataType : 'json',
              success : function(result){
                  if(result.status=="Done"){

                  $("#postResultDiv").html("<p style='background-color:#7FA7B0; color:white; padding:20px 20px 20px 20px'>" + 
                          "Post Successfully! <br>" +
                          "---> Release's Info: ReleaseName = " + 
                          result.data.name + " ,CodeCutOffDate = " + result.data.inputcutoffdate + " ,ReleaseDate = " + result.data.releaseDate+" ,Status = " + result.data.status+  "</p>");
                  }
                  else
                      {

                      $("#postResultDiv").html("<strong>Error</strong>");
                      }
                  console.log(result);
              },
              error : function(e)
              {
                  alert("Error");
                  console.log("ERROR: ",e);
                  $("#postResultDiv").html("<p style='background-color:#7FA7B0; color:white; padding:20px 20px 20px 20px'>" + 
                          "Post Successfully! <br>" +
                          "---> Customer's Info: ReleaseName = " + 
                          result.data.name + " ,CodeCutOffDate = " + result.data.inputcutoffdate + " ,ReleaseDate = " + result.data.releaseDate+" ,Status = " + result.data.status+  "</p>");
              }
         });
         resetdata();
      }
      function resetdata(){
          $("#name").val("");
          $("#inputcutoffdate").val("");
          $("#releaseDate").val("");
          $("#status ").val("");
      }
    });

问题: 每当我运行作为html文件的代码时,只要单击一下按钮,它就会调用ajax函数,因此它进入了ajax调用。在我测试邮递员时,所有控制器在邮递员中都运行良好,但是从ajax函数不会进入url,并在else部分中显示错误。在Spring mvc中,使用Rest API和MYsql。任何人都可以对此提供见解,那就太好了。

0 个答案:

没有答案