编码AJAX POST数据的URL

I was using encodeURIComponent to encode an URL but I'm getting 500 SERVER ERROR on some urls, I'm sure the problem is in the encoding since removing the data solves the error completely.

How do I encode the URL so that I can retrieve it in the other end and not have problems in the call?

    $.ajax({type:'POST',url: "/insert-url.php", data: 'url='+encodeURIComponent(link)',
        success:function(data_response){
            }
        });
$.ajax({type:'POST',url: "/insert-url.php", 
        data: 'url='+encodeURIComponent(link)**-->'<---**,
        success:function(data_response){
        }
});

a ' too much