Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Ajax requests inside admin section


Go to End


3 Posts   1693 Views

Avatar
folibis

Community Member, 13 Posts

1 May 2013 at 9:10pm

Hi All
My question is about admin section. I have a custom page with set of fields. One of them is «Tags» with many-to_many relation. So I have list with my tags and I can select a few of them without problem. But also I need to add new tag without reloading the page. I guess Ajax is good for this. I am familiar with Ajax, Javascript, PHP but I have no idea how to do that with Silverstripe.

Avatar
folibis

Community Member, 13 Posts

2 May 2013 at 8:29am

The night gone but i sttill search for way to do that.
Is there any tutorial or doc how Silverstripe build his path to objects?
I mean, for example, if I edit my page of type ArticlePage with path /admin/pages/edit/show/7 so how can I access controller of this page rather function GetList() from this controller?

Avatar
LoFonz

Community Member, 12 Posts

13 June 2013 at 8:39pm

Edited: 13/06/2013 8:45pm

yop.

Not sure the thread is still up, but basically, to run an ajax request in SS3, this is how I did :

Include your JS in the "getCMSFields" function of your controller :

class MyController extends Page{
public function getCMSFields() {
Requirements::javascript('mysite/javascript/javascript.js');
}
}

This file will be loaded on pages of type "MyControrller".

In the javascript.js (that's an example. I call an ajax request everytime I change the value of a dropdownfield) :

jQuery(document).ready(function($) {
$.entwine('ss', function($){
$("#Form_EditForm_MarqueID").entwine({
onchange : function() {
//alert(this.val());
$.ajax({
url: '/mysite.be/myadmin/getModels?marqueid='+this.val(), //mysite.be refers to your website of course.
type:'GET',
success: function(){
console.log('it worked);
},
error: function(){
console.log('it failed');
}
});
}
});
});
});

I hope I answered your question.

EDIT : I found a usefull thread, even if it's old, I think it can be useful :) http://www.silverstripe.org/customising-the-cms/show/7893