jQuery Ajax 500错误

I'm trying to connect my html with MongoDB. The data are successfully entered, but the ajax won't start. I'm going to make sure what i enter is in my database (a login form). Here's my code:

.controller('LoginCtrl', function($scope, $state, $location, $ionicPopup) {
     $scope.login = function(data) {
           var formdata = {

                   phone : $("#phone").val(),
                   pin : $("#pin").val()    
            };

            var Jformdata = JSON.stringify(formdata);
            console.log(Jformdata);

            $.ajax({

                url : "/SinarmasProject/Submit",
                context : document.body,
                type : 'POST',
                data : Jformdata,
                contentType : "application/json; charset=utf-8",
            }).done(function (response){

                if(response == "true"){
                    $location.path('/login/main/dash');
                }else if(response == "false"){
                    $scope.showAlert('Nomer Telephone dan PIN Salah');
                }

            });
}
})

The error turns out like this:

 POST http://localhost:8089/SinarmasProject/Submit 500 () jquery-3.1.0.min.js:4
send @ jquery-3.1.0.min.js:4
ajax @ jquery-3.1.0.min.js:4
$scope.login @ controllers.js:41
$parseFunctionCall @ ionic.bundle.js:20628
(anonymous function) @ ionic.bundle.js:52854
$eval @ ionic.bundle.js:22684
$apply @ ionic.bundle.js:22783
(anonymous function) @ ionic.bundle.js:52853
eventHandler @ ionic.bundle.js:11297
triggerMouseEvent @ ionic.bundle.js:2863
tapClick @ ionic.bundle.js:2852
tapMouseUp @ ionic.bundle.js:2922


EDIT: My controller.java

    package com.spring.controller;

    import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.mongodb.core.MongoTemplate;
    import org.springframework.data.mongodb.core.query.Criteria;
    import org.springframework.data.mongodb.core.query.Query;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import com.spring.beans.BankBean;

    @Controller
    public class controller {

        @Autowired
        private MongoTemplate mongotemplate;

        @RequestMapping(value="/BankMasuk", method= {RequestMethod.GET})
        //@ResponseBody
        public List<BankBean> BankMasuk(){
            List<BankBean> BankBean =  mongotemplate.find(new Query(), BankBean.class);
            return BankBean;
        }

        @RequestMapping(value="/Submit", method={RequestMethod.POST})
        @ResponseBody 
        public String SubmitBtn(@RequestBody BankBean bank){

            String temp;
            String string1 = bank.getPhone();
            String string2 = bank.getPin();
            Query query = new Query();
            query.addCriteria(Criteria.where("phone").is(string1));
            BankBean person = mongotemplate.findOne(query, BankBean.class);


            if(string1.equals(person.getPhone()) && string2.equals(person.getPin())){
                temp = "true";
            }else{
                temp="false";
            }


            return temp;
        }

    }

EDIT: BankBean

package com.spring.beans;

public class BankBean {
    public String phone;
    public String pin;
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getPin() {
        return pin;
    }
    public void setPin(String pin) {
        this.pin = pin;
    }
    @Override
    public String toString() {
        return "BankBean [phone=" + phone + ", pin=" + pin + "]";
    }

}

1个回答


尝试使用</ p>

  .fail(函数(数据){
警报(数据);
});
</ code> </ pre>

在您的jquery中,以了解有关edit和fail的错误语法的更多信息</ p>

  .done(函数(数据){
         xxx;
     })。fail(函数(jqXHR,textStatus){
         xxx;
     })
</ code> </ pre>
     </ div>

展开原文

原文

try to use

.fail (function(data){
alert(data);
});

in your jquery to know more about the error syntax of edit and fail

    .done(function (data) {
        xxx;
    }).fail(function (jqXHR, textStatus) {
        xxx;
    })

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐