如何使用get参数和post请求发送ajax请求

时间:2016-09-29 10:55:13

标签: javascript jquery ajax

我试过这种方式,但提出了错误的请求

  var id = localStorage.getItem('sessionId');
     $.ajax({
        method:'POST',
        url:'video/ratings?sessionId='+id+'',
        data:{"videoId":"5757e6e41b0a244b256ac1d7","rating":"5"},
        success:function(data){
        console.log(data); 
        } 
     }

 );
  

这些是我用

提供的输入
(required)queryurl:/video/ratings?sessionId=CqqAfowuZLzXHyViPaYzzyOU3dGPCFaG
input:{"videoId":"5757e6e41b0a244b256ac1d7","rating":"5"}

2 个答案:

答案 0 :(得分:0)

尝试下面的代码,这对我有用。

 var id = localStorage.getItem('sessionId');
         $.ajax({
            headers: {'session_id': id}
            method:'POST',
            url:'video/ratings/',
            data:{"videoId":"5757e6e41b0a244b256ac1d7","rating":"5"},
            success:function(data){
            console.log(data); 
            } 
         });

答案 1 :(得分:0)

var id = localStorage.getItem('sessionId');
     $.ajax({
        method:'POST',
        url:'video/ratings?sessionId='+id+'',
        data:{videoId:"5757e6e41b0a244b256ac1d7",rating:5},
        success:function(data){
        console.log(data); 
        } 
     }

);