2013-12-16 167 views
0

大家好,我正在開發電話差距項目並使用ajax Web服務。我使用下面的代碼發送請求:不支持的媒體類型錯誤

var credentials = { 
         "name": "nouman", 
         "email": "[email protected]", 
         "mobile_number": 03324412764, 
         "employee_number": 4556, 
         "gender": 1, 
         "password": "1234567891234567", 
         "language": 1 
        }; 

      function GetMember() { 
       $.ajax({ 
        type: 'POST', 
        url: 'http://192.168.1.103:8080/mazaya_cms/signup.htm', 
        //data: "{'name': 'nouman','email': '[email protected]','mobile_number': 03324412764,'employee_number': 4556, 'gender': 1,'password': '1234567891234567','language': 1}", 
        data: JSON.stringify(credentials), 
        //data: '{"id": "nouman","name":"nouman"}', 
        contentType: "application/json; charset=utf-8", 
        dataType: 'json', 
        crossDomain: true, 
        success: OnGetMemberSuccess, 
        error: OnGetMemberError 
       }); 
      } 
      GetMember(); 
      function OnGetMemberSuccess(data, status) { 
       alert(data+ " "+status); 
      } 

      function OnGetMemberError(request, status, error) { 
       alert(request+" "+error+ " "+status); 
      } 

我得到錯誤代碼:415不支持的媒體類型,請幫幫我!

回答

0

我已經成功地解決了這個問題

var credentials = { 
       "name": "nn", 
       "email": "nn%40gmail.com", 
       "mobile_number": 03324412764, 
       "employee_number": 4556, 
       "gender": 1, 
       "password": "1234567891234567", 
       "language": 1 
      }; 

     $.ajax({ 
      url: "http://192.168.1.103:8080/mazaya_cms/signup.htm", 
      type: "post", 
      data: credentials, 
      dataType : "json", 
      success: function(request, status, error){ 
      alert("success "+request.status); 
       }, 
      error:function(jqXHR, textStatus, errorThrown) { 
       alert("failure"+errorThrown); 
       } 
     }); 
相關問題