Hot answers tagged

9

It's fairly easy to create an AJAX add to cart button using Store. It's no different from any other AJAX form submission. This used to be in our user guide, but SE is a much better place for "how to" questions so I'll summarize here: The general process is: Create your sidebar cart as a separate template Embed your sidebar cart inside a known div element ...


5

It's certainly possible without hacking. Just that the EE documentation isn't particularly helpful on how to handle this sort of thing. Basically, you want to write a Module. Then you need to register an "action" in your module's install script: $data = array( 'class' => 'Module_name' , 'method' => 'method_to_call' ); $this->EE->...


5

You can use $this->EE->output->send_ajax_response($array); for the same purpose.


5

You can do this if you're willing to programmatically manipulate hidden configuration variables in your config file ;-) I use Focus Labs Master Config style configs, so I have this in my dev config: $env_config['template_debugging'] = 'y'; $env_config['show_profiler'] = 'y'; And, obviously, you can set those to 'n' by-hand to turn off the debugger ...


4

The main problem here is this: keywords="{segment_3}" You probably don't have keywords in the third segment, but an entire encoded query. You're feeding that query as keywords to the URL tag, essentially encoding it twice. If you use the URL tag and you want to work from an existing search action, use query="{segement_3}" to pass all the details from the ...


4

You're currently accessing the template from the wrong URL. EE writes URL's based off the template groups from the root of the site: index.php/template_group/template_name. If you're removing index.php from the URL, just remove it from the snippet below and this should work: $(element).load("index.php/snippets/newswall_news");


4

This works for logging into ExpressionEngine with ajax and showing the appropriate error, you would just modify the code where it checks for the error messages it returns to display to the user. You will need more conditions for the required fields. function displayAjaxMessage(message, response_id) { if(typeof(response_id)==="undefined") response_id = "#...


4

You can avoid the XID validation by making a GET request instead of a POST request. XID validation only occurs when secure_forms is y and the $_POST array is not empty. Or you can generate a valid XID hash by using {XID_HASH} in your template. Maybe something like: <body data-xid="{XID_HASH}"> <script> $.post( 'site/inifinite_scroll_ajax', ...


4

After some guidance from Ahmad Saad below (thanks Ahmad!) I was able to get shipping (and total) calculated after shipping method change. First it will require to change template where shipping form field is located. That part is required due to default shipping value is not loaded when new cart created (in my case). My looks like: <tr> <td>...


4

ExpressionEngine has a protection against Cross-site Request Forgery - CSRF and a documentation available here. You just have to add that line to your form: <input type="hidden" name="csrf_token" value="{csrf_token}"> And send the data in your AJAX request. I had the same problem today and that fixed it for me.


3

Yes, it's possible (assuming you're talking about triggering the ExpressionEngine status message in the control panel, not generically setting flash data from an AJAX request). I had this same question a few days ago - I know for example the CP template manager triggers the success message at the top of the page from an AJAX request, so I went trawling ...


3

In order to make this work with Store 2.0 / EE 2.7 you need to make an extra template with a form so a new XID is generated. After the ajax request to the cart, make a new ajax request to the template with the form. Get the xid from that template and update the xid on your orignal template jquery / ajax: url = 'ajaxform' $.get(url, function(returnData) { ...


3

Posting the solution for future reference here. There were two parts to this problem. Firstly, it looks like the template partial which was being loaded via ajax had slightly different code than the main template, so for example was using {price} instead of {price_inc_tax}. This caused different price to be displayed for products loaded later on via AJAX. ...


3

I see you're already attempting to grab the new XID from the return data of the Ajax call: // update the XID hash in the form so we don't run afoul of EE's secure forms $("input[name=XID]").val(response.XID); But I fell onto this documentation the other day which I think is new and relating to new EE version handling. Seems like if submitted by Ajax the ...


3

Create a hidden template that is just the logged in username only. Then load it in via jquery ajax .load(); Once login is complete as well. if (event.success) { member_favourites = "5"; //do something $("div#username").load("_username.html"); }


3

I don't think so unless you write a plugin to access the code in the DB. However you could easily create a hidden template IE ( _parsed_data.html). Then AJAX load it in to your to your current template using Jquery AJAX .load(). $("div#parsedData").load("{site_url}/templategroup/_parsed_data.html"); You can also with javascript depending on how you ...


3

I wouldn't recommend this but in cases where you have no choice, e.g. you cannot tweak the code in an app in time or something to that effect, you can opt to conditionally disable secure forms in your config.php or bootstrap. E.g. // Make an exception to make AJAX forms app-compatible // EE 2.7.x introduced mandatory XIDs even for AJAX, but an app won't ...


3

Honestly, I wouldn't even mess with that plugin since that's what it's supposed to do. Just do a simple ajax call and append the data like this. Note the move of #articles to the main template, and paginate_base parameter in the embed template. Main Template <html> <head></head> <body> <section id="articles"> ...


2

Interesting...I added if ($_SERVER['SERVER_PORT'] != 443) { $config['assets_site_url'] = "http://".$_SERVER['HTTP_HOST']."/"; } else { $config['assets_site_url'] = "https://".$_SERVER['HTTP_HOST']."/"; } and it worked. I wonder why the override was needed? Thanks Brandon!


2

I've thought more about this. Based on the pre-condition you're building a custom addon to handle this, the only way I can see it working would be to either : Create a dummy top level template group (ie. called 'api' with a sole tag to your custom addon : {exp:restful_api:handle}. From within there you could do any and all the parsing/restful interactions ...


2

With a custom extension, you could. Just use the insert_comment_end hook, then do something like this: if(ee()->input->is_ajax_request()) { ee()->extensions->end_script = TRUE; $data['comment_id'] = $comment_id; $data['moderated'] = $comment_moderate; echo json_encode($data); }


2

Yes, you need to get a new XID each time via Ajax and update your form hidden value, so next time the form is submitted it uses the new XID. Depends what your Ajax is returning of course and where it's submitting to, but in the past on return from the Ajax submission, I've fired another function to just do an Ajax request, then do the replacements. For ...


2

YYYYYYEEEEEEEEESSSSSSSS!!!! Thank F for that. I have got this working. Peter's answer was the right way to go. It was in the docs all along! For those that may run into a similar situation, I fixed this by adding the recommend ajaxPrefilter that is mentioned in the docs - with a little tweak to define the form. An updated JS Fiddle: http://jsfiddle.net/...


2

Do you have Process form data in Secure Mode? set to "Yes" in your Security and Session Preferences? That could be your issue. If you do, then EE will give a "The action you have requested is invalid." error message instead of using your template, and you'll never be able to get your POST data. I tried your code and it works as long as Process form data in ...


2

You can use send_ajax_response() which will return JSON and works well for response to ajax requests. For your example you'd do public function mealDates() { $array = array( 'foo' => 'bar', ); return $ee()->output->send_ajax_response($array); }


2

I usually do all of my AJAX form submissions with the jquery ajax form plugin. This allows you to customize the experience for your users here is the link to the plugin its very simple to implement. http://malsup.com/jquery/form/ Hope this helps!


2

Use stash to cache the results (refresh every x minutes, overwrite=no) for fast access. Chain your ajax request, and use channel:entries limit and offset parameters (e.g. after the first 50 return, hand them to map handler and call same/next ajax with new offset) Option 2 will do several requests in a row, which might not be what you want. edit: example ...


2

...and also a checkbox that will show whether the user has completed that resource You can't store the member choices in the channel entries information. Well, technically you could, but it would have to store every members details so not optimal and not recommended. I'm assuming there could be a crossover - so 2 courses could share the same resource. So ...


2

I checked and I can see the XID param being sent to the jquery.ajax by looking in chrome network panel, i can see the query string it builds. So we are good there. It sounds like you are sending the XID in GET instead of POST data. CSRF tokens must be present in the POST data if POST data is received by ExpressionEngine. 2.7.3: POST: XID 2.8+: POST: ...


2

Move the click handler to the wrapping div. $('#cal_container').on('click', '#prev, #next', function(event) { event.preventDefault(); /* Act on the event */ }); Has to do with the original event handler in your code not being passed to the dynamically inserted html. There's a good explanation found here: http://toddmotto.com/attaching-event-...


Only top voted, non community-wiki answers of a minimum length are eligible