Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying a message in a dialog box using AJAX, jQuery, and CakePHP
    primarykey
    data
    text
    <p>I have a form, and when users submit this form, it should pass the data along to a function using AJAX. Then, the result of that is displayed to the user in a dialog box. I'm using CakePHP (1.3) and jQuery to try and accomplish this but I feel like I'm running into the ground.</p> <p>The form will eventually be used for uploading images with tags, but for now I just want to see a message pop up in the box..</p> <p>The form:</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;create('Image', array('type' =&gt; 'file', 'controller' =&gt; 'images', 'action' =&gt; 'upload', 'method' =&gt; 'post')); echo $this-&gt;Form-&gt;input('Wallpaper', array('type' =&gt; 'file')); echo $this-&gt;Form-&gt;input('Tags'); echo $this-&gt;Form-&gt;end('Upload!'); ?&gt; </code></pre> <p>The AJAX:</p> <pre><code>$(document).ready(function() { $("#ImageUploadForm").submit(function() { $.ajax({ type: "POST", url: "/images/upload/", data: $(this).serialize(), async: false, success: function(html){ $("#dialog-modal").dialog({ $("#dialog-modal").append("&lt;p&gt;"+html+"&lt;/p&gt;"); height: 140, modal: true, buttons: { Ok: function() { $(this).dialog('close'); } } }) } }); return false; }); }); </code></pre> <p>NOTE: if I put <code>$("#dialog-modal").dialog({ height: 140, modal: true });</code> OUTSIDE of the <code>$.ajax</code> but inside the <code>$("#ImageUploadForm").submit(function() {</code> and comment out the <code>$.ajax</code> stuff, I WILL see a dialog box pop up and then I have to click it for it to go away. After this, it will not forward to the location <code>/images/upload/</code> </p> <p>The method that AJAX calls:</p> <pre><code> public function upload() { $this-&gt;autoRender = false; if ($this-&gt;RequestHandler-&gt;isAjax()) { echo 'Hi!'; exit(); } } </code></pre> <p>$this->RequestHandler->isAjax() seems to do either absolutely nothing, or it is always returning false. I have never entered an if statement with that as the condition.</p> <p>Thanks for all the help, if you need more information let me know. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload