开发者

Calling ( triggering ) a link after the submit

How could I call (trigger) a link after th开发者_JAVA技巧e form submits ? I'd like the function to call a link so that the new jQuery div is called on its own after the button submits an upload. The infoUp() function doesn't work..

HTML:

<a href="#" id="profile">Profile</a>

<form name="updatePicForm" action="page1.php" method="post" enctype="multipart/form-data">
<span style="font-size:12px">&nbsp;Picture upload size 1 MB&nbsp;</span>
<input type="file" name="uploadPic" class="forms" id="picForm"/>
<input type="submit" name="submitPic"  value="Go" id="submitPic" onClick="infoUp();"/>
<!--<span class="style3">&nbsp;2 MB max&nbsp;</span>-->
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
</form> 

//jQuery:

function infoUp() { 
$(document).ready(function() { 
$("#profile").trigger('click');
});


If you do a regular form submit, then the document will be replaced with the result of the form post, so no further JavaScript will execute. What you need to do is use "AJAX" techniques to send a post request without replacing the current page.

This is a pretty big redesign because you need to change the PHP handler for the URL you're posting to so it just processes the post and change your client-side code so it updates through JavaScript instead of through replacing the document.


You need to use Ajax to process both server (submit) and client(infoUp) action simultaneously. Else client action will become invalid.


You can do:

// when the form is submitted
$('form').submit(function(){

  // run your infoUp function
  infoUp()

  // sends the form info off
  return true

})

But this would not help much, because submitting the form would send you to another page.

You should probably submit the form via ajax like this:

// when the form is submitted
$('form').submit(function(){

  // sends the form info off
  // callback function executes after form data is sent
  $.post('page1.php',$('form').serialize(),function(){

      // run your infoUp function
      infoUp()

  })

  // prevent form from submitting normal request
  return false

})

This code is all untested, but should give enough insight into how to go about it

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜