春天mongodb ajax badrequest

时间:2017-07-03 11:20:47

标签: java spring spring-mvc

我正在尝试使用ajax更新文章数据,但我收到400(错误请求)错误。我认为问题与json有关,但我无法找到实际问题所在。

Article.class模型

$scope.getAllArticles = function() {
    inventoryService.allArticles().then(
            function(data, textStatus, response){     
                $scope.articles = data;
                $scope.$apply();
            },
            function (response, textStatus, errorThrown) {
                console.error("Failed to fetch all articles!", response);
            }
    );
}

$scope.fillTheStocks = function(article) {
    inventoryService.fillTheStocks(article).then(
            function(data, textStatus, response){     
                $scope.getAllArticles();
            },
            function (response, textStatus, errorThrown) {
                console.error("Failed to refill article!", response);
            }
    );
}

文章ajax文件:

InventoryController.js

this.fillTheStocks = function(article){
    console.log(article);
    console.log(JSON.stringify(article));
     return $.ajax({ url: "/SBZProjekat/api/article/fillTheStocks", 
            type: "POST", 
            data: JSON.stringify(article),
            contentType: "application/json"
            });
}

InventoryService.js

@Controller
@RequestMapping(value="/api/article")
public class ArticleRestController {

  @Autowired
  private ArticleService articleService;

  @RequestMapping(value="/fillTheStocks", method = RequestMethod.POST,   produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public ResponseEntity<?> fillTheStocks(@RequestBody Artikal article)
  { 
     article.setBrojnoStanje(article.getMinimalnoStanje());
     articleService.saveArticle(article);

    return new ResponseEntity(HttpStatus.OK);
  }

}

Spring控制器:

POST http://localhost:8080/SBZProjekat/api/article/fillTheStocks 400 (Bad Request)
Failed to refill article! Object {readyState: 4, responseText: "<html><head><title>Error</title></head><body>Bad Request</body></html>", status: 400, statusText: "Bad Request"}

我在Chrome控制台中收到此错误:

<table class="col-lg-12 table table-hover">
        <tr>
          <th>Code</th>
          <th>Name</th>
          <th>Category</th>
          <th>Price</th>
          <th>Akcija</th>
          <th>Razlog narudzbine</th>
          <th></th>
        </tr>
        <tr ng-repeat="article in articles track by $index">
            <td>{{ article.sifra}}</td>
          <td>{{ article.naziv }}</td>
          <td>{{ article.kategorija.naziv }}</td>
          <td>{{ article.cena }}</td>
          <td>TODO akcija</td>
          <td data-ng-if="article.daLiPopunitiZalihe">Nedostaje {{ article.minimalnoStanje - article.brojnoStanje }} {{ article.naziv }}</td>
          <td data-ng-if="article.daLiPopunitiZalihe" class="clickable ta-mid" data-ng-click="fillTheStocks(article)">
            <span class="glyphicon glyphicon-plus" style="color: green;"></span>
        </td>
         </tr>
    </table>

HTML函数调用:

Question.objects.filter(choice_set__isnull=False)

0 个答案:

没有答案