2014-07-23 31 views
0
我想提出一個跨域AJAX POST打到我休息的WebService

jQuery的Ajax調用被不正確發送的GET而不是POST

這是我的HTML代碼

$(document).on("click", ".submit", function(e) { 

var name = $('#name').val(); 
var mobile = $('#mobile').val(); 
var email = $('#email').val(); 

if(name==''||mobile==''||email=='') 
{ 
    alert('Please Fill All the Details'); 
return false; 
} 
else 
{ 
var information = { 
    "name": name, 
    "mobile": mobile, 
    "email": email 
} 

var dataaa = JSON.stringify(information); 

console.log(dataaa); 

    $.ajax({ 
      type: 'POST', 
     url: 'http://192.168.2.46:8080/PostEx/test/testservice', 
      jsonpCallback: 'jsonCallback', 
      cache: true, 
      data: dataaa, 
      dataType: 'jsonp', 
      jsonp: false, 
      success: function (response) { 

       alert(response); 
      }, 
      error: function (e) { 
       $("#divResult").html("WebSerivce unreachable"); 
      } 
     }); 

} 

}); 

<body> 

<form method="POST"> 
<div class="required"> 
Name: <input class="required" type="text" id="name" name="name"> <span class="asterisk_input"> </span> </br> 
Phone: <input type="mobile" id="mobile" name="mobile"> <span class="asterisk_input"> </span> </br> 
E-mail: <input type="email" id="email" name="email"> <span class="asterisk_input"> </span> </br> 
</div> 
    <input class="submit" type="submit"> 
</form> 
</body> 

我的瀏覽器下觀察控制檯

enter image description here

很抱歉的大圖像,我不知道如何裁剪圖片。

+0

這可能有所幫助:http://stackoverflow.com/a/7605119/1059101 – Jai

回答

2

使用JSONP時,您無法發出POST請求。

JSONP請求不使用XMLHTTPRequest對象執行請求,它通過將資源加載爲Javascript來向請求的頁面添加script標記。 script標記沒有指定請求方法的方法,它始終是GET請求。

+0

好的,謝謝你的解釋。 – Pawan

相關問題