2014-02-12 40 views
-2

我收到{error:請使用post request}。這裏是我試過的代碼:在html中使用java腳本代碼以消耗java中的webservices

$(document).ready(function() { 
    $("#btn").click(function (event) { 
     var uid = document.getElementById("fpsid").value; 
     var pwd = document.getElementById("Pass").value; 
     var dataString = "{ 'fpsid' : '" + uid + "', 'Pass' : '" + pwd + "'}"; 

     $.ajax({ 
      ServiceCallID: 1, 
      url: "http://epds.nic.in/PossWebService/services/Poss?wsdl", 
      type: 'POST', 
      data: dataString, 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 

      success: function (result) { 
       returnVal = result.d; 
       alert(returnVal); 
      }, 

      error: function (XMLHttpRequest, textStatus, errorThrown) { 
       returnVal = ''; 
      } 
     }); 
    }); 
}); 
+0

編輯爲您的文章。這不屬於評論。 –

+0

你有js小提琴嗎? – Konza

+1

什麼是'ServiceCallID'應該是? – jasonscript

回答

0

開始,dataStringvalid JSONObject keys must be double quoted.爲此,給定一個對象比字符串連接有更好的方式來生成JSON。使用JSON.stringify()

dataString = JSON.stringify({ 
    fpsid: uid, 
    Pass: pwd 
}); 

或只是讓jQuery的擔心:

var postData = { 
    fpsid: uid, 
    Pass: pwd 
}; 

$.ajax({ 
    // ... 
    data: postData, 
    // ... 
});