Ich habe versucht, nach einer Lösung zu suchen, aber ich habe ein Problem versucht zu bestimmen, was zu suchen ist. Ich versuche, AJAX für eine PHP-Get-Anfrage zu verwenden, und es scheint zu reichen (wie das Verlassen der Seite).AJAX BitMovin - GET-Anfrage funktioniert nicht
Ich benutze die BitMovin-Bibliothek, die das Problem zu sein scheint. Der Code funktioniert für das Starten eines Livestreams, der AJAX jedoch nicht. Wenn ich den BitMovin-Code auskommentiere, funktioniert der AJAX.
Was passiert, wenn die Anforderung mit BitMovin Code uncommented ausgeführt wird, öffnet es diese Seite (Es wird angenommen, die Anfrage im Hintergrund zu vervollständigen):
{ "data": { "success" : true, "message" : "Success!" } }
Das Skript:
<?php
use bitcodin\AwsRegion;
use bitcodin\Bitcodin;
use bitcodin\VideoStreamConfig;
use bitcodin\AudioStreamConfig;
use bitcodin\Job;
use bitcodin\JobConfig;
use bitcodin\Input;
use bitcodin\S3InputConfig;
use bitcodin\EncodingProfile;
use bitcodin\EncodingProfileConfig;
use bitcodin\ManifestTypes;
use bitcodin\Output;
use bitcodin\S3OutputConfig;
use bitcodin\GcsOutputConfig;
use bitcodin\HttpInputConfig;
use bitcodin\LiveStream;
require_once './vendor/autoload.php';
//more code for my site
if (!empty($errors)) {
$data['success'] = false;
$data['errors'] = $errors;
}else{
Bitcodin::setApiToken('---my-key-removed-for-post---');
$encodingProfileConfig = new EncodingProfileConfig();
$encodingProfileConfig->name = 'Encoding Name';
$low = new VideoStreamConfig();
$low->bitrate = 1000000;
$low->height = 480;
$low->width = 854;
$encodingProfileConfig->videoStreamConfigs[] = $low;
$audio = new AudioStreamConfig();
$audio->bitrate = 128000;
$encodingProfileConfig->audioStreamConfigs[] = $audio;
$encodingProfile = EncodingProfile::create($encodingProfileConfig);
$outputConfig = new S3OutputConfig();
$outputConfig->name = "OutputName";
$outputConfig->accessKey = "--removed-for-post---";
$outputConfig->secretKey = "--removed-for-post---";
$outputConfig->bucket = "bucketName";
$outputConfig->region = AwsRegion::US_WEST_2;
$outputConfig->prefix = 'folder/test';
$outputConfig->makePublic = false;
$output = Output::create($outputConfig);
$liveInstance = LiveStream::create('StreamName', 'StreamKey', $encodingProfile, $output, 0);
while($liveInstance->status != $liveInstance::STATUS_RUNNING)
{
sleep(2);
$liveInstance->update();
if($liveInstance->status == $liveInstance::STATUS_ERROR)
{
$errors['bitmovin'] = 'Error with bitmovin';
$data['errors'] = $errors;
//throw new \Exception("Error occurred during Live stream creation");
}
}
$rtmpUrl = "";
$rtmpUrl = $liveInstance->rtmpPushUrl;
$streamInstanceId = $liveInstance->id;
$data['success'] = true;
$data['message'] = 'Success!';
}
echo json_encode($data);
?>
Dies ist der AJAX-Code.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#start").click(function(event){
var formData = {};
$.ajax({
type : 'GET',
url : './foobar.php',
data : formData,
dataType : 'json',
encode : true
}).done(function(data) {
console.log(data);
});
event.preventDefault();
});
});
</script>
</head>
<body>
<p><a href="#" id="start">Start</a></p>
</body>
</html>
Also ich weiß, es ist der BitMovin-Code, warum öffnet es den Code in einer neuen Seite?
Vielen Dank im Voraus.
Event.preventDefault() zu finden; feuert nicht. Vergessen Sie nicht, es in Ihre Argumente einzufügen ändern Sie diese '$ (" # start "). Klicken Sie auf (function() {' zu diesem '$ (" # start "). Click (function (event) {' – Conceptz
@Conceptz Ja, tut mir leid das ist da. Einfach kopieren und falsch einfügen – Keith