I have an API which has an example written in PHP. Unfortunately I need to write in in JavaScript but lack the knowledge to convert it myself.
Are there any online converters or documentation which may be able to help me?
Taking an example I have tarted but cannot finish as I do not understand the php code:
PHP:
//Creates a HTTP Request by given URL & arguments.
function httpGetT($url, $arg = '') {
$sargs = '';
if(is_array($arg)) {
foreach($arg as $k => $v) {
if(strlen($sargs)) $sargs .= '&';
$sargs .= $k.'='.urlencode($v);
}
}
if(strlen($sargs)) $sargs = '?'.$sargs;
$file_stream = @fopen($url.$sargs, 'r');
if($file_stream) {
$response = '';
while($data_row = fread($file_stream, 1024)) {
$response .= $data_row;
}
fclose($file_stream);
return $response;
}
else {
return false;
}
}
JavaScript:
function HttpGet(url, arg) {
var args = '';
if (arg == Array) {
$.each(arg, function() {
if (arg.length > 0) {
}
});
}
}
Of course if there is any documentation which can help me as there is a lot of code to copy and transfer.