zoukankan      html  css  js  c++  java
  • post跨域请求webservice接口

      尝试解决这个问题花费将近一天时间,又好好对ajax理解了一遍。问了别人调过webservice接口的人说都是用post请求,然后post请求就不能用jsonp跨域,然后改了一下ajax,

    $.ajax({
      type: "post",
      //contentType: "application/json;charset=utf-8", //如果是xml则WebService 会返回xml类型 
      url: url,
      dataType: "json",
      //jsonp: 'jsoncallback',
      data:{
        Interface:"",
        Interface_method:"",
        xmlData:""
      },
      /*beforeSend: function (x) { 
        x.setRequestHeader("Content-Type", "application/xml; charset=utf-8"); 
      }, */
      success: function (response) { //回调函数,result,返回值 
        console.log(response);
        alert(1);
      },
      error:function(msg,textStatus,xhr){
        console.log(msg);
        alert(textStatus);
        console.log(xhr.responseText);
      });

      不知道问题在哪的时候用这个判断一下:

    error:function(){ 
        alert(XMLHttpRequest.status);
        alert(XMLHttpRequest.readyState);
        alert(textStatus);
      }

      一直跳到error函数,报500的错误,控制台输出一串:

    Object {readyState: 4, responseText: "<?xml version="1.0" encoding="utf-8"?><soap:Envelo…etail /></soap:Fault></soap:Body></soap:Envelope>", status: 500, statusText: "Internal Server Error"}

      原来以为是跨域问题没解决,看一下headers发现后台有加请求头,现在真是懵逼了

  • 相关阅读:
    模板-树链剖分
    bzoj2523 聪明的学生
    P1220 关路灯
    BZOJ3572 [Hnoi2014]世界树
    BZOJ4013 [HNOI2015]实验比较
    BZOJ4012 [HNOI2015]开店
    BZOJ4011 [HNOI2015]落忆枫音
    BZOJ4009 [HNOI2015]接水果
    BZOJ4010 [HNOI2015]菜肴制作
    BZOJ4008 [HNOI2015]亚瑟王
  • 原文地址:https://www.cnblogs.com/yaoya/p/7093238.html
Copyright © 2011-2022 走看看