Salut. Se da functia
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$("#generarmt").click(function() {
masthemes();
});
});
function masthemes(){
var url = 'http://api.themoviedb.org/3/movie/';
var imdbLink = $('input[name=imdbLink]').get(0).value;
var mod = '?append_to_response=images,trailers';
var lang = '&language=ro&include_image_language=ro,null';
var key_api = '&api_key=bc5288bc42cd815be9403df38fe93ca6';
$.getJSON( url + imdbLink + mod + lang + key_api, function(masthemes) {
$.each(masthemes, function(key, val) {
if(key == "genres"){
var genr = "";
$.each( masthemes.genres, function( i, item ) {
genr += "" + item.name + ", ";
genr1 = item.name;
$('input[name=newcategory]').val( genr1 );
$('#category-add-submit').trigger('click');
$('#category-add-submit').prop("disabled", false);
$('input[name=newcategory]').val("");
});
$('input[name=' +key+ ']').val( genr );
}else if(key == "trailers"){
var tral = "";
$.each( masthemes.trailers.youtube, function( i, item ) {
tral += "[" + item.source + "]";
});
$('input[name=' +key+ ']').val( tral );
}else if(key == "images"){
var imgt = "";
$.each( masthemes.images.backdrops, function( i, item ) {
imgt += item.file_path + "\n";
});
$('textarea[name=' +key+ ']').val( imgt );
}else if(key == "release_date"){
$('input[name=' +key+ ']').val( val.slice(0,4) );
$('#new-tag-fecha').val( val.slice(0,4) );
}else if(key == "title"){
$('input[name=' +key+ ']').val(val);
$('label#title-prompt-text').addClass('screen-reader-text');
$('input[name=post_title]').val(val);
}else{
$('input[name=' +key+ ']').val(val);
}
});
});
$.getJSON( url + imdbLink + "/credits?" + key_api, function(masthemes) {
$.each(masthemes, function(key, val) {
if(key == "cast"){
var cstm = cstml = "";
$.each( masthemes.cast, function( i, item ) {
cstm += "[" + item.profile_path + ";" + item.name + "," + item.character + "]";
cstml += "" + item.name + ", "; //
});
$('textarea[name=' +key+ ']').val( cstm );
$('#new-tag-actor').val( cstml );
}else{
var crew_d = crew_dl = "";
var crew_w = crew_wl = "";
$.each( masthemes.crew, function( i, item ) {
if(item.department == "Directing"){
crew_d += "[" + item.profile_path + ";" + item.name + "]";
crew_dl += "" + item.name + ", "; //
}
if(item.department == "Writing"){
crew_w += "[" + item.profile_path + ";" + item.name + "]";
crew_wl += "" + item.name + ", "; //
}
});
$('input[name=crew_director]').val( crew_d );
$('input[name=crew_writ]').val( crew_w );
$('#new-tag-director').val( crew_dl );
$('#new-tag-escritor').val( crew_wl );
}
});
});
}
// ]]></script>
Care este actionata de butonul :
<input id="generarmt" type="button" value="Generate" />
Cum pot actiona asupra functiei fara buton ci pur si simplu sa deschid o pagina noua .php : exemplu
test.php?id=tt242423 (id fiind GET-ul)
functia sa faca acelas lucru ca acum dar sa fie actionata pur si simplu de deschiderea unei pagini, fara sa apas acel buton…