There are files file1.php and file2.php. how, when loading the first file, transfer the variable value to the second file with ajax-ohm and place the result of the second file execution in the body of the first file?

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> <script> function collapsElement(id) { if ( document.getElementById(id).style.display != "none" ) { document.getElementById(id).style.display = 'none'; } else { document.getElementById(id).style.display = ''; } } function changeArrows(id) { if ( document.getElementById(id).className != "arrow_down" ) { document.getElementById(id).className = 'arrow_down'; } else { document.getElementById(id).className = 'arrow_up'; } } </script> <style type="text/css"> .arrow_up{ background-position: right; background-image: url('/bitrix/templates/darshan/img/arrow-up.png'); background-repeat: no-repeat; background-size: 16px; } .arrow_down{ background-position: right; background-image: url('/bitrix/templates/darshan/img/arrow-down.png'); background-repeat: no-repeat; background-size: 16px; } </style> <?$divIdCount = 1;?> <div class="news-list"> <?foreach($arResult["ITEMS"] as $arItem){?> <article class="row post type-post status-publish format-standard entry category-article"> <div class="large-9 medium-8 small-9 columns"> <div id="element<?=$divIdCount?>" style="display: none; margin-left: 25px;"> <section class="entry"> <p><?=$arItem["PREVIEW_TEXT"];?></p> <? $props = array(); $obj = CIBlockElement::GetList( array("SORT" => "ASC"), array("IBLOCK_ID" => $arResult["ID"], "SECTION_ID" => $arParams["PARENT_SECTION"], "ID" => $arItem["ID"]), array("ID", "IBLOCK_ID", "NAME", "PROPERTY_FILE_PATH") ); while ($value = $obj->GetNext()) { $props[] = $value; } if (strlen($props[0]["PROPERTY_FILE_PATH_VALUE"]) > 0) { $APPLICATION->IncludeComponent("bitrix:player","",Array( "PLAYER_TYPE" => "auto", "USE_PLAYLIST" => "Y", "PATH" => $props[0]["PROPERTY_FILE_PATH_VALUE"], "PLAYLIST_DIALOG" => "", "PROVIDER" => "video", "STREAMER" => "", "WIDTH" => "640", "HEIGHT" => "360", "PREVIEW" => "", "SKIN_PATH" => "/bitrix/components/bitrix/player/mediaplayer/skins", "SKIN" => "bitrix.swf", "CONTROLBAR" => "bottom", "WMODE" => "transparent", "LOGO" => "/logo.png", "LOGO_LINK" => "http://ваш_сайт.com/", "LOGO_POSITION" => "bottom-left", "ADDITIONAL_FLASHVARS" => "", "WMODE_WMV" => "window", "SHOW_CONTROLS" => "Y", "AUTOSTART" => "N", "REPEAT" => "list", "VOLUME" => "90", "MUTE" => "N", ) ); } ?> </section><!-- /.entry --> </div> <header> <h2 class="title entry-title"> <div id="arrows<?=$divIdCount?>" class="arrow_down" onClick="changeArrows('arrows<?=$divIdCount?>')"> <a href="javascript:collapsElement('element<?=$divIdCount?>')" rel="nofollow"> <b><?=$arItem["NAME"]?></b> </a> </div> </h2> </header> <?if ($arItem['IBLOCK_SECTION_ID'] != 14):?> <div class="post-meta"> <abbr class="date time published updated" title="<?echo $arItem["DISPLAY_ACTIVE_FROM"]?>"><?echo $arItem["DISPLAY_ACTIVE_FROM"]?></abbr> </div> <?endif;?> </div> <div class="large-3 medium-4 small-3 columns"> <?if($arParams["DISPLAY_PICTURE"]!="N" && is_array($arItem["PREVIEW_PICTURE"])):?> <a href="<?=$arItem["DETAIL_PAGE_URL"]?>"> <img class="thumbnail" src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>" alt="<?=$arItem["PREVIEW_PICTURE"]["ALT"]?>" /> </a> <?endif?> </div> </article> <?$divIdCount++?> <?}?> <?if($arParams["DISPLAY_BOTTOM_PAGER"]):?> <br /><?=$arResult["NAV_STRING"]?> <?endif;?> </div> 

This is the code for the entire page. in a separate file you need to make this section

 <? $APPLICATION->IncludeComponent("bitrix:player","",Array( "PLAYER_TYPE" => "auto", "USE_PLAYLIST" => "Y", "PATH" => $props[0]["PROPERTY_FILE_PATH_VALUE"], "PLAYLIST_DIALOG" => "", "PROVIDER" => "video", "STREAMER" => "", "WIDTH" => "640", "HEIGHT" => "360", "PREVIEW" => "", "SKIN_PATH" => "/bitrix/components/bitrix/player/mediaplayer/skins", "SKIN" => "bitrix.swf", "CONTROLBAR" => "bottom", "WMODE" => "transparent", "LOGO" => "/logo.png", "LOGO_LINK" => "http://ваш_сайт.com/", "LOGO_POSITION" => "bottom-left", "ADDITIONAL_FLASHVARS" => "", "WMODE_WMV" => "window", "SHOW_CONTROLS" => "Y", "AUTOSTART" => "N", "REPEAT" => "list", "VOLUME" => "90", "MUTE" => "N", ) ); } ?> 

and in the array element with the "PATH" key you need to transfer the value from $props[0]["PROPERTY_FILE_PATH_VALUE"]

  • It is necessary to specify the question, add the code and description of what happened and what does not - Mr. Black
  • one
    something tells me that there is no need for ajax there, but I just need the usual include or, which is even simpler, to make the file code as a function and use it. - KoVadim 7:42 pm
  • @KoVadim, require_once or erquire ? :) - Mr. Black
  • @Doofy frankly, fought a couple of hours, and the travel code, suitable for display, did not work. I will try to describe in words. the page is loaded, it is executed, relatively speaking, the first half of the code and the value of the variable is calculated. Further, before executing the second half of the code, using ajax, the value of the variable is transferred to another file and the result of executing the other file is loaded before the second half of the code. I hope it was clearer to describe it ... - Islam
  • one
    Need more information. How does html look, where to embed? All this can be done in one php file, if everything goes through the requests - Mr. Black

1 answer 1

I do not know what $APPLICATION returns and whether echo will pass to it

One document is loaded, the page is bypassing the isset , when prompted, it works and returns to the same page an answer that inserts into .entry

index.php

 <?php if(isset($_POST['player'])) { echo "<div>player</div>"; exit(); } ?> <html> <body> <section class='entry'></section> </body> <script src='script.js'></script> </html> 

script.js

 xhr = new XMLHttpRequest(); xhr.open('POST', '', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send('player='); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { document.querySelector('.entry').innerHTML = xhr.responseText; } } 

You can also try to disable page caching, which is better if nothing is loaded except for the player.

 <html> <head> <meta http-equiv='Cache-Control' content='no-cache'> </head> </html> 
  • $ APPLICATION is a class object, it contains information about the page and auxiliary methods. it turns out that I am putting the player code into a separate file, and instead I am writing code <? php ...?>? - Islam
  • @ Islam, in theory, yes, but I do not see where the player is inserted specifically. The player code can not be made into a separate file, it can be placed in the same document, inside if(isset($_POST['player'])) { ... } . Maybe the object itself returns something, I'm not familiar with the bitrix - Mr. Black
  • This whole piece of code is the player code. This is the component for playing the video itself cms. Thank you very much! tomorrow I will understand. you set the direction, otherwise I didn’t know where to dig))) - Islam