开发者

zend, how to use jquery ajax to submit a form?

i have a Zend Form and i would like to use jquery to do some ajax posting.

if ($this->getRequest()->isPost()) {
$data = $form->getValues();
$image_id = $this->usermedia->crop_image($userObj->user_id, $data);
}

the crop_image saves the data:

$new_image_id = $this->getDbTable()->createRow($new_row_data)->save();
return $new_image_id;

if the form is posted then run a function and give me back an $new_image_id.

all this hap开发者_StackOverflow中文版pens in a modal window that loads a iframe with the form.

what i want is when i submit the form to grab that $new_image_id from inside the iframe, close the modal window and place it on my original page

any ideas on how this can be done?

thanks

edit:


Just render that variable into a javascript variable:

var newImageId = "<?php echo $new_image_id ?>";

Then you can use:

http://api.jquery.com/load/

jQuery's wonderful .load() method to send that id to an external PHP page that then pulls it from the database and renders it to HTML. .load() will pull that all back in to your current page. You can then define a callback from .load() which gets rid of the modal.

Edit:

If your code is such that rendering the variable to a javascript variable is not practical, you can render it to the DOM itself, say as an element attribute... then get it using .content()

jQuery/JavaScript: accessing contents of an iframe

Bear in mind same origin policy:

http://en.wikipedia.org/wiki/Same_origin_policy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜