小编bsi*_*zle的帖子

使用XMLHttpRequest发布到ASP.Net Core WebAPI时出现错误415

使用WebAPI后端服务器处理新项目,我无法从实际网站发布到控制器,尽管Postman没有问题发布到控制器.我收到错误415,浏览器控制台记录:

HTTP415: UNSUPPORTED MEDIA TYPE - The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
(XHR)OPTIONS - http://localhost:5000/api/Users
Run Code Online (Sandbox Code Playgroud)

来自Kestrel的日志是

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 OPTIONS http://localhost:5000/api/Users  0
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 OPTIONS http://localhost:5000/api/Users  0
info: Microsoft.AspNetCore.Mvc.StatusCodeResult[1]
      Executing HttpStatusCodeResult, setting HTTP status code 415
Microsoft.AspNetCore.Mvc.StatusCodeResult:Information: Executing HttpStatusCodeResult, setting HTTP status code 415
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action SchoolsChat.Controllers.UserContoller.Post (SchoolsChat) in 2.5323ms
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed …
Run Code Online (Sandbox Code Playgroud)

c# asp.net xmlhttprequest typescript asp.net-core

10
推荐指数
2
解决办法
2万
查看次数

在AJAX调用后ReactJS重新渲染

学习反应,虽然我理解组件的生命周期,但我不明白,虽然我的JSON调用成功但它不会呈现我最初提取的项目列表.当我向列表添加新项目时,它会进行渲染,但这需要我单击编辑按钮并添加新元素.

var InterBox = React.createClass({
    getInitialState: function(){
        return {
            "content" : [],
            "editing" : false,
            "pulled" : false
        }
    },
    componentDidMount: function(){
        var url = "http://jsonplaceholder.typicode.com/posts";
        var tempdata = this.state.content;
        $.getJSON(url, function(data){
            for (var i = 0; i < data.length; i++) {
                var element = data[i];
                tempdata.push(element.body);
                console.log(tempdata);
            }
        });
        this.setState({"content":tempdata});
        this.forceUpdate();
    },
    addContent: function(e){
        var currentContent = this.state.content;
        currentContent.push(this.refs.content.value);
        this.refs.content.value = "";
        this.setState({"content" : currentContent, "editing" : false});
        this.render();
    },
    changeMode: function(e){
        this.setState({"editing": true});
        this.render();
    },
    render: function(){
        if …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery reactjs

2
推荐指数
1
解决办法
2042
查看次数