OctoberCMS Javascript API AJAX call to a component function to update component's partial









up vote
0
down vote

favorite












So I have the following file structure:



plugins/myname/pluginname/components/pluginname/default.htm
plugins/myname/pluginname/components/PluginName.php


default.htm acts as the partial of the component.
and I have the following JS API



setInterval(function()
$.request('onEverySecond',
update: '@default.htm':'#rate-marquee',
complete: function()
console.log('Finished!');

)
, 1000);


onEverySecond is a function in PluginName.php that updates a variable called fx thrown to default.htm.



At the front end the partial default.htm seems to be updated, but it refreshes the whole partial which is not what I want, it causes the marquee to replay again and again and only be able to show the first few piece of contents.
All I wanted is that the AJAX will update only the variable fx where the data is updated.



How can I achieve that?



EDIT 1:



Here is the partial markup:



% set fx = __SELF__.fx %
<marquee id="rate-marquee" name="rate-marquee" onmouseover="this.stop();" onmouseout="this.start();">
<ul>
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %
</ul>
</marquee>


Additionally, here is the code in PluginName.php



public function onRun()

$this->addJs('/plugins/SoyeggWebDevelopment/fxmarquee/assets/js/default.js');
$this->updateFX();



public function onEverySecond()

$this->updateFX();


public $fx;


So updateFX() works perfectly well too.










share|improve this question























  • can you share partial markup and fx variable used.
    – Hardik Satasiya
    Nov 10 at 7:39










  • @HardikSatasiya thanks for your repsonse. the variable was updated perfectly every second upon the marquee refreshes. However the whole marquee refreshes everytime so the marquee restarts the loop again and again. I updated the markup and please have a look, thank you!
    – warmjaijai
    Nov 12 at 3:07















up vote
0
down vote

favorite












So I have the following file structure:



plugins/myname/pluginname/components/pluginname/default.htm
plugins/myname/pluginname/components/PluginName.php


default.htm acts as the partial of the component.
and I have the following JS API



setInterval(function()
$.request('onEverySecond',
update: '@default.htm':'#rate-marquee',
complete: function()
console.log('Finished!');

)
, 1000);


onEverySecond is a function in PluginName.php that updates a variable called fx thrown to default.htm.



At the front end the partial default.htm seems to be updated, but it refreshes the whole partial which is not what I want, it causes the marquee to replay again and again and only be able to show the first few piece of contents.
All I wanted is that the AJAX will update only the variable fx where the data is updated.



How can I achieve that?



EDIT 1:



Here is the partial markup:



% set fx = __SELF__.fx %
<marquee id="rate-marquee" name="rate-marquee" onmouseover="this.stop();" onmouseout="this.start();">
<ul>
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %
</ul>
</marquee>


Additionally, here is the code in PluginName.php



public function onRun()

$this->addJs('/plugins/SoyeggWebDevelopment/fxmarquee/assets/js/default.js');
$this->updateFX();



public function onEverySecond()

$this->updateFX();


public $fx;


So updateFX() works perfectly well too.










share|improve this question























  • can you share partial markup and fx variable used.
    – Hardik Satasiya
    Nov 10 at 7:39










  • @HardikSatasiya thanks for your repsonse. the variable was updated perfectly every second upon the marquee refreshes. However the whole marquee refreshes everytime so the marquee restarts the loop again and again. I updated the markup and please have a look, thank you!
    – warmjaijai
    Nov 12 at 3:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











So I have the following file structure:



plugins/myname/pluginname/components/pluginname/default.htm
plugins/myname/pluginname/components/PluginName.php


default.htm acts as the partial of the component.
and I have the following JS API



setInterval(function()
$.request('onEverySecond',
update: '@default.htm':'#rate-marquee',
complete: function()
console.log('Finished!');

)
, 1000);


onEverySecond is a function in PluginName.php that updates a variable called fx thrown to default.htm.



At the front end the partial default.htm seems to be updated, but it refreshes the whole partial which is not what I want, it causes the marquee to replay again and again and only be able to show the first few piece of contents.
All I wanted is that the AJAX will update only the variable fx where the data is updated.



How can I achieve that?



EDIT 1:



Here is the partial markup:



% set fx = __SELF__.fx %
<marquee id="rate-marquee" name="rate-marquee" onmouseover="this.stop();" onmouseout="this.start();">
<ul>
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %
</ul>
</marquee>


Additionally, here is the code in PluginName.php



public function onRun()

$this->addJs('/plugins/SoyeggWebDevelopment/fxmarquee/assets/js/default.js');
$this->updateFX();



public function onEverySecond()

$this->updateFX();


public $fx;


So updateFX() works perfectly well too.










share|improve this question















So I have the following file structure:



plugins/myname/pluginname/components/pluginname/default.htm
plugins/myname/pluginname/components/PluginName.php


default.htm acts as the partial of the component.
and I have the following JS API



setInterval(function()
$.request('onEverySecond',
update: '@default.htm':'#rate-marquee',
complete: function()
console.log('Finished!');

)
, 1000);


onEverySecond is a function in PluginName.php that updates a variable called fx thrown to default.htm.



At the front end the partial default.htm seems to be updated, but it refreshes the whole partial which is not what I want, it causes the marquee to replay again and again and only be able to show the first few piece of contents.
All I wanted is that the AJAX will update only the variable fx where the data is updated.



How can I achieve that?



EDIT 1:



Here is the partial markup:



% set fx = __SELF__.fx %
<marquee id="rate-marquee" name="rate-marquee" onmouseover="this.stop();" onmouseout="this.start();">
<ul>
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %
</ul>
</marquee>


Additionally, here is the code in PluginName.php



public function onRun()

$this->addJs('/plugins/SoyeggWebDevelopment/fxmarquee/assets/js/default.js');
$this->updateFX();



public function onEverySecond()

$this->updateFX();


public $fx;


So updateFX() works perfectly well too.







javascript ajax octobercms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 3:14

























asked Nov 9 at 3:22









warmjaijai

2601718




2601718











  • can you share partial markup and fx variable used.
    – Hardik Satasiya
    Nov 10 at 7:39










  • @HardikSatasiya thanks for your repsonse. the variable was updated perfectly every second upon the marquee refreshes. However the whole marquee refreshes everytime so the marquee restarts the loop again and again. I updated the markup and please have a look, thank you!
    – warmjaijai
    Nov 12 at 3:07

















  • can you share partial markup and fx variable used.
    – Hardik Satasiya
    Nov 10 at 7:39










  • @HardikSatasiya thanks for your repsonse. the variable was updated perfectly every second upon the marquee refreshes. However the whole marquee refreshes everytime so the marquee restarts the loop again and again. I updated the markup and please have a look, thank you!
    – warmjaijai
    Nov 12 at 3:07
















can you share partial markup and fx variable used.
– Hardik Satasiya
Nov 10 at 7:39




can you share partial markup and fx variable used.
– Hardik Satasiya
Nov 10 at 7:39












@HardikSatasiya thanks for your repsonse. the variable was updated perfectly every second upon the marquee refreshes. However the whole marquee refreshes everytime so the marquee restarts the loop again and again. I updated the markup and please have a look, thank you!
– warmjaijai
Nov 12 at 3:07





@HardikSatasiya thanks for your repsonse. the variable was updated perfectly every second upon the marquee refreshes. However the whole marquee refreshes everytime so the marquee restarts the loop again and again. I updated the markup and please have a look, thank you!
– warmjaijai
Nov 12 at 3:07













1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Here problem seems you are replacing whole marquee it causes to re-render it.




To solve this we can just update portion inside marquee






setInterval(function()
$.request('onEverySecond',
complete: function()
console.log('Finished!');

)
, 1000);



We don't do anything special here just a simple ajax call




to update portion of marquee we need to assign id to it and we define internal partial





<marquee id="rate-marquee" 
name="rate-marquee"
onmouseover="this.stop();" onmouseout="this.start();">
<ul id='rate-marquee-inner'> <!-- <= here -->
% partial __SELF__ ~ '::_marquee_inner' %
</ul>
</marquee>



_marquee_inner.htm partila markup






% set fx = __SELF__.fx %
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %


and to update that portion we just need to return markup array





function onEverySecond() 
$this->updateFX();
return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')];




this will just push new updated markup to given id #rate-marquee-inner so now it will just update inner portion of marquee and marquee will not re-render.




if any doubt please comment.






share|improve this answer




















  • Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
    – warmjaijai
    Nov 13 at 6:25










  • I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
    – warmjaijai
    Nov 13 at 6:36










  • is it working for you ?
    – Hardik Satasiya
    Nov 13 at 7:20










  • It is now! thanks a lot!
    – warmjaijai
    Nov 13 at 7:37










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219393%2foctobercms-javascript-api-ajax-call-to-a-component-function-to-update-component%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Here problem seems you are replacing whole marquee it causes to re-render it.




To solve this we can just update portion inside marquee






setInterval(function()
$.request('onEverySecond',
complete: function()
console.log('Finished!');

)
, 1000);



We don't do anything special here just a simple ajax call




to update portion of marquee we need to assign id to it and we define internal partial





<marquee id="rate-marquee" 
name="rate-marquee"
onmouseover="this.stop();" onmouseout="this.start();">
<ul id='rate-marquee-inner'> <!-- <= here -->
% partial __SELF__ ~ '::_marquee_inner' %
</ul>
</marquee>



_marquee_inner.htm partila markup






% set fx = __SELF__.fx %
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %


and to update that portion we just need to return markup array





function onEverySecond() 
$this->updateFX();
return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')];




this will just push new updated markup to given id #rate-marquee-inner so now it will just update inner portion of marquee and marquee will not re-render.




if any doubt please comment.






share|improve this answer




















  • Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
    – warmjaijai
    Nov 13 at 6:25










  • I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
    – warmjaijai
    Nov 13 at 6:36










  • is it working for you ?
    – Hardik Satasiya
    Nov 13 at 7:20










  • It is now! thanks a lot!
    – warmjaijai
    Nov 13 at 7:37














up vote
1
down vote



accepted










Here problem seems you are replacing whole marquee it causes to re-render it.




To solve this we can just update portion inside marquee






setInterval(function()
$.request('onEverySecond',
complete: function()
console.log('Finished!');

)
, 1000);



We don't do anything special here just a simple ajax call




to update portion of marquee we need to assign id to it and we define internal partial





<marquee id="rate-marquee" 
name="rate-marquee"
onmouseover="this.stop();" onmouseout="this.start();">
<ul id='rate-marquee-inner'> <!-- <= here -->
% partial __SELF__ ~ '::_marquee_inner' %
</ul>
</marquee>



_marquee_inner.htm partila markup






% set fx = __SELF__.fx %
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %


and to update that portion we just need to return markup array





function onEverySecond() 
$this->updateFX();
return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')];




this will just push new updated markup to given id #rate-marquee-inner so now it will just update inner portion of marquee and marquee will not re-render.




if any doubt please comment.






share|improve this answer




















  • Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
    – warmjaijai
    Nov 13 at 6:25










  • I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
    – warmjaijai
    Nov 13 at 6:36










  • is it working for you ?
    – Hardik Satasiya
    Nov 13 at 7:20










  • It is now! thanks a lot!
    – warmjaijai
    Nov 13 at 7:37












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Here problem seems you are replacing whole marquee it causes to re-render it.




To solve this we can just update portion inside marquee






setInterval(function()
$.request('onEverySecond',
complete: function()
console.log('Finished!');

)
, 1000);



We don't do anything special here just a simple ajax call




to update portion of marquee we need to assign id to it and we define internal partial





<marquee id="rate-marquee" 
name="rate-marquee"
onmouseover="this.stop();" onmouseout="this.start();">
<ul id='rate-marquee-inner'> <!-- <= here -->
% partial __SELF__ ~ '::_marquee_inner' %
</ul>
</marquee>



_marquee_inner.htm partila markup






% set fx = __SELF__.fx %
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %


and to update that portion we just need to return markup array





function onEverySecond() 
$this->updateFX();
return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')];




this will just push new updated markup to given id #rate-marquee-inner so now it will just update inner portion of marquee and marquee will not re-render.




if any doubt please comment.






share|improve this answer












Here problem seems you are replacing whole marquee it causes to re-render it.




To solve this we can just update portion inside marquee






setInterval(function()
$.request('onEverySecond',
complete: function()
console.log('Finished!');

)
, 1000);



We don't do anything special here just a simple ajax call




to update portion of marquee we need to assign id to it and we define internal partial





<marquee id="rate-marquee" 
name="rate-marquee"
onmouseover="this.stop();" onmouseout="this.start();">
<ul id='rate-marquee-inner'> <!-- <= here -->
% partial __SELF__ ~ '::_marquee_inner' %
</ul>
</marquee>



_marquee_inner.htm partila markup






% set fx = __SELF__.fx %
% for item in fx %
<li>
item.Item : item.BID % if item.Revalue == 0 % <div class="arrow-up"></div> % else % <div class="arrow-down"></div> % endif %
</li>
% endfor %


and to update that portion we just need to return markup array





function onEverySecond() 
$this->updateFX();
return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')];




this will just push new updated markup to given id #rate-marquee-inner so now it will just update inner portion of marquee and marquee will not re-render.




if any doubt please comment.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 9:56









Hardik Satasiya

4,7821822




4,7821822











  • Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
    – warmjaijai
    Nov 13 at 6:25










  • I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
    – warmjaijai
    Nov 13 at 6:36










  • is it working for you ?
    – Hardik Satasiya
    Nov 13 at 7:20










  • It is now! thanks a lot!
    – warmjaijai
    Nov 13 at 7:37
















  • Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
    – warmjaijai
    Nov 13 at 6:25










  • I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
    – warmjaijai
    Nov 13 at 6:36










  • is it working for you ?
    – Hardik Satasiya
    Nov 13 at 7:20










  • It is now! thanks a lot!
    – warmjaijai
    Nov 13 at 7:37















Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
– warmjaijai
Nov 13 at 6:25




Thanks Hardik, now it returns error The partial '_marquee_inner.htm' is not found. showing the error happens in default.htm, so somehow % partial __SELF__ ~ '::_marquee_inner' % is not reading the partial that I already created. Couldn't see any typo
– warmjaijai
Nov 13 at 6:25












I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
– warmjaijai
Nov 13 at 6:36




I figure it out. There are some changes in the code to be made: cannot use return ['#rate-marquee-inner' => $this->renderPartial('_marquee_inner.htm')]; it turns out to show only the code in _marquee_inner.htm without even the layout. and it also needs @ before the htm to reference component's partial. secondly, I delete the above mentioned line and do the update in js instead so it only update the ul update: '@_marquee_inner.htm':'#rate-marquee-inner',
– warmjaijai
Nov 13 at 6:36












is it working for you ?
– Hardik Satasiya
Nov 13 at 7:20




is it working for you ?
– Hardik Satasiya
Nov 13 at 7:20












It is now! thanks a lot!
– warmjaijai
Nov 13 at 7:37




It is now! thanks a lot!
– warmjaijai
Nov 13 at 7:37

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219393%2foctobercms-javascript-api-ajax-call-to-a-component-function-to-update-component%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3