嗨,我是JSON新手。我的問題是如何通過AJAX將JSON數據傳遞給安靜的Web服務?如何通過ajax將JSON數據傳遞給restful web服務以及如何獲取JSON數據?
請幫幫我。
我試圖通過下面的代碼,但我不知道這件事
我的索引頁
<script type="text/javascript">
$(document).ready(function(){
var uname = document.getElementById("uname").value();
var password = document.getElementById("pwd").value();
$('#ok').click(function(){
$.ajax({
url:'http://localhost:8090/LoginAuthRWS/rest/orders',
type:'post',
dataType: 'Jsondemo',
success: function(data) {
$('#name').val(data.name);
$('#email').val(data.email);
var JSONObject= {
"uname":uname,
"password":password
};
}
});
});
});
</script>
感謝Ur的幫助Arvind –
使用JSON.stringify返回一個代表javascript對象的json字符串。 JSON.parse將字符串轉換爲javascript對象 – micha
您錯過了contentType:'application/json' – Arashsoft