How can I send POST data and navigate with JQuery?

前端 未结 4 1931
[愿得一人]
[愿得一人] 2021-01-02 19:51

On my blog I have a lot of

 blocks containing code snippets.

What I want to do is add a .click() handler to all the

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 20:19

    Not sure I would handle it this way, probably I would simply pop up a dialog with the code rather than leave the page, but you could handle this by building a form using javascript then triggering a submit on that form instead of using AJAX.

    Using dialogs with jQuery UI:

     $('pre').on('click', function() {
          $('

    ' + $(this).text() + '

    ').dialog({ ... set up dialog parameters ... }); });

    Build a form

     $('pre').on('click', function() {
          var text = $(this).text();
          $('')
              .appendTo('body');
          $('[name="code"]').val(text);
          $('.hidden-form').submit();
     });
    

提交回复
热议问题