如何在Ajax调用中传递原始数据?

时间:2017-08-21 07:52:30

标签: jquery ajax

在邮政人员中,我们将其作为原始数据包含在体内 的 grant_type =密码&安培;用户名=管理员&安培;密码=管理员

我们如何在Ajax中编写相同的东西?我们如何将它传递给Ajax的数据参数?

$.ajax({
    url : "/",
    type: "POST",
    **data: JSON.stringify([
        {id: 1, name: "Shahed"}, 
        {id: 2, name: "Hossain"}
    ]),**--------> how do we pass above grant type here ?
    contentType: "application/json; charset=utf-8",
    dataType   : "json",
    success    : function(){
        console.log("Pure jQuery Pure JS object");
    }
});

1 个答案:

答案 0 :(得分:0)

请尝试以下代码,

$.ajax({
   method     : "POST",
   url        : "/",
   dataType   : "json",
   data       : { grant_type: "password", username: "admin",password:"admin" }
 })
.done(function( msg ) {
    alert( "Data Saved: " + msg );
 });
相关问题