user3732793 user3732793 - 6 months ago 8
Javascript Question

JSON call with url as parameter

this does work fine as long the homepage var has no // in it

$.getJSON(url + "/addPerson/'" + name + "'/'" + homepage +"'", function(data){console.log(data);} );

how would I correctly prepare an url var to pass it as JSON call ?


If homepage is an URL with http:// in it you need encode it.

You should write :

$.getJSON(url + "/addPerson/" + name + "/" + encodeURIComponent(homepage), function(data){console.log(data);} );

If that is the case, you should not pass urls in urls. Use the POST payload or multiform data.

Also, if the aim of the request is to add a record in your database, use POST instead of GET.

$.post(url+'/addPerson', {name: name, homepage: homepage}, function(data){console.log(data);});