Welcome Guest, Not a member yet? Register   Sign In
Two important CJAX questions

Hello dear buddies
I hope some users or perhaps Ajaxboy himself can help us on this issue.

We are using CJAX in conjuction with CI for one of our projects and now we encountered these two problems:

1. When clicking an AJAX-enabled button (button A) that updates some part of page with another button, let's call it button B, how to bind some other ajax-based action to the second button (Button B) ? (for example a like / Unlike scenario that clicking like will bring Unlike button)

2. While using uploader plugin, in some client-side state we don't want the file selection be validated and it doesn't care if no file is selected so that file submit is not prevented. We even thought of using two forms but strangely it any form submit will raise the validation.

Help will be deeply appreciated

- M Amroabadi

There is more than one way to accomplish this. I'll run some tests, let me get back to you on this one.

Thank you dude!
Waiting hard for the reply :-)

Sorry for the delayed response.

<b>For question #1,</b>

here is a sample, (sorry i didn't have time to do this sooner):

Lets take this existing sample as our model:


Here are the aspects:

It uses files: examples/click_ajax_request.php, examples/controllers/click_ajax_request.php

in the controller, I did this after adding div1 in the html:
class controller_click_ajax_request {

function click_button($message)
  $ajax = ajax();

  $ajax->update("div1","&lt;input type='button' value='ButtonB' id='buttonb'&gt;");

  $ajax->click('buttonb', $ajax->alert('Hello!'));

It simply adds html to the div, will create a new button, called ButtonB, and when you click buttonb, it will alert "Hello!", like wise you can add any (and as many as you want) other cjax function instead of the alert. This is a basic example, you should be able to add any commands to your newly created elements.

There is a a different "callback" way to accomplish that will be allowed in newer version, by using the plugins technology but it hasn't been tested for this specific purpose so it might need work to work for this purpose, (currently is used to allow the execution of other plugins and other plugins methods).

<b>Question #2</b>

If you look in the example plugin uploader ( http://cjax.sourceforge.net/examples/plu...loader.php )

$uploader = $ajax->uploader('btn_saveForm', null,
//settings are optional
  'url' => 'ajax.php?upload_file/post', //post request after files are uploaded
  'suffix' => md5(time(). rand(1,10000000)), // makes files names universally unique,
  'debug' => 'Debug Option is turned on this Demo.',
  'success_message' => 'File(s) @files successfully uploaded.', //@files tag is replaced by files uploaded.
  'ext' => array('jpg','gif', 'png','jpeg'),
  'no_files' => 'Please select a file'

Just comment out 'no_files', and it should not display the warning message when no files are chosen.



Theme © iAndrew 2016 - Forum software by © MyBB