Gaurav Aggarwal Gaurav Aggarwal - 6 months ago 11
Ajax Question

Passing : in URL parameter for jquery ajax call

Hi I am trying to fetch values from Envato using

jQuery.ajax()
, the URL parameter contains a colon which is not accepted by system.

$('button').click(function(){
var request=$.ajax(
url: "https://api.envato.com/v1/market/random-new-files:themeforest.json",
type: "GET",
connection: "keep-alive",
contentType: "application/json",
mimeType: "application/json ",
headers: {
"Authorization": 'Bearer uO5xtTUXgJMyYPKg5fC9NNRGcue42QeD'
}
)}
request.done(function (msg) {
console.log(msg);
})


This is the call, but I am getting error as per following screenshots: http://prntscr.com/b7poyo
http://prntscr.com/b7pp1b

Answer

Try the following:

   $('button').click(function() {
     var request = $.ajax({
       url: "https://api.envato.com/v1/market/random-new-files:themeforest.json",
       type: "GET",
       connection: "keep-alive",
       contentType: "application/json",
       mimeType: "application/json ",
       headers: {
         "Authorization": 'Bearer uO5xtTUXgJMyYPKg5fC9NNRGcue42QeD'
       },
       success: function(data) {
         console.log(data)
       }
     })
   });

https://jsfiddle.net/2ukdh27r/