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发现后台有加请求头,现在真是懵逼了

  • 相关阅读:
    安卓SharedPreferences类的使用
    安卓登录案例
    如何用Android Studio查看build.gradle源码
    学点Groovy来理解build.gradle代码
    build.gradle代码
    【Android】TextView文字长度测量和各种Paddding解析
    【Android】TextView跑马灯效果
    【分享】学长的安利来了~~O(∩_∩)O
    【Android】Fragment懒加载和ViewPager的坑
    【Android】你应该知道的调试神器----adb
  • 原文地址:https://www.cnblogs.com/yaoya/p/7093238.html
Copyright © 2011-2022 走看看