0

i tried this way but geting a bad request

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

 );

these are inputs i have given with

(required)queryurl:/video/ratings?sessionId=CqqAfowuZLzXHyViPaYzzyOU3dGPCFaG
input:{"videoId":"5757e6e41b0a244b256ac1d7","rating":"5"}
Mohi Indharan
  • 65
  • 1
  • 10

2 Answers2

0

try below code , it is work for me.

 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); 
            } 
         });
chirag satapara
  • 1,947
  • 1
  • 15
  • 26
  • so... you are converting query parameter to be part of the path? how does it conform to the original code? – Vladimir M Sep 29 '16 at 11:03
  • i am using a PHP ,in backend i code like this for get url: `$app->get('/video/:field1/:field2','authenticate', function($id, $field) {` – chirag satapara Sep 29 '16 at 11:05
  • ya @Vladimir i'm using the correct path, is there some other fault in my codde – Mohi Indharan Sep 29 '16 at 11:08
  • @MohiIndharan your requests should correspond to what your server expects. The question is how are you reading the request on the server. Are you expecting JSON or uri-encodded form? Are you expecting any session variables as cookies, etc. – Vladimir M Sep 29 '16 at 11:13
  • @MohiIndharan , i change in to the my answer ,have a look – chirag satapara Sep 29 '16 at 11:13
  • @VladimirM , `$headers = apache_request_headers();` , in this you can get all the header which is with your request – chirag satapara Sep 29 '16 at 11:15
  • @chiragpatel thanks :). but the question was from a bit different perspective. Now HOW, but how he is using this information. – Vladimir M Sep 29 '16 at 11:18
  • @MohiIndharan then you might want to specify the content type as: contentType: "application/json", – Vladimir M Sep 29 '16 at 11:19
  • see this for reference: http://stackoverflow.com/questions/17426199/jquery-ajax-and-json-format – Vladimir M Sep 29 '16 at 11:19
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); 
        } 
     }

);

toto
  • 1,180
  • 2
  • 13
  • 30