zoukankan      html  css  js  c++  java
  • WCF Rest post请求

    只有遇到问题才能解决问题,这个问题之前也遇到过因为没有及时总结所以这个问题又重新出现困扰了我8个小时. ajax 请示WCF Rest 是一个比较成熟的技术.所以 涉及到了几个技术点

    1 jquery ajax 的理解 . 应该设置contentType  : application/json

    2 C# 解析json字符串的格式  错误认为写成'{"brands":1}' 和写成 "{'brands':1}"是一样,但是实际上C#格式字符时只认 '{"brands":1}'这一种。

    3 WCF 中设置

     [OperationContract]
            [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] 

    成功调用的代码如下

        function Test3() {
    
    
    
                if (confirm("确认发布")) {
    
                    var webMethod = "http://localhost:19920/Services/Service1.svc/DeployExchangerate3";
    
                    var data = 1;
    
                    $.ajax({
                        url: webMethod,
                        //data: { key: "a", page: 1 },
                        data: '{"brands":1}',
                        dataType: "json",
                        jsonp: "callback",
                        processData:false,
                        contentType:"application/json; charset=utf-8",
                        type:"POST",
                        success: function (data) {
    
                            if (data == true) {
                                alert("确认成功!");
    
                            }
                        },
                        error: function (data, status, error) {
                            alert(error);
                          
                            $("#error").html(data.responseText)
                        }
                    }
            );
                }
            }
  • 相关阅读:
    Linux:文件解压与压缩
    Linux:环境变量
    Linux:Vim
    Linux:目录&文件基本操作
    Linux:文件权限
    Linux:用户&用户组操作
    Linux:Shell 常用通配符
    Linux:常用shell快捷键
    Linux:Linux 重要人物
    架构:层次化
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/4155425.html
Copyright © 2011-2022 走看看