kylefox / jquery-modal

The simplest possible modal for jQuery
http://jquerymodal.com/
Other
2.61k stars 661 forks source link

Help with loading ajax db data #209

Closed lcsqlpete closed 7 years ago

lcsqlpete commented 7 years ago

I'm hoping to convert an existing page on my website to use jquery-modal. It's a form for purchasing concert tickets. The data is loaded into the form using an Ajax call to get it from a database. I see ajac examples but they all seem to be aimed at reading the form layout from an external file rather than loading data into it.

Any pointers to get me on the right track much appreciated.

gorillamoe commented 7 years ago

Here you go:

<button id=demo_btn1>Inception</button>
<script>
(function(window, document){
  var btnCb = function() {
    $.ajax({url: "dummy.json", success: function(result) {
      var list = document.createElement('ul');
      var _cb = function(i, ds) {
        var keys = Object.keys(ds);
        keys.forEach(function(k){
          if (typeof ds[k] !== "object") {
            var tmp = document.createElement('li');
            tmp.innerHTML = k + " : " + ds[k];
            list.appendChild(tmp);
          }
        });
      };
      $(result).each(_cb);
      $(list).appendTo('body').modal();
    }});
  };
  demo_btn1.onclick = btnCb;
})(window, document);
</script>

Here's a working example

lcsqlpete commented 7 years ago

Great, thanks Marco. In my case, I'll already have the modal defined on the page, just need to fill in some elements on it from the ajax call. I assume I can use a similar technique? Pete

On Mon, Jul 24, 2017 at 2:33 AM, Marco Kellershoff <notifications@github.com

wrote:

Here you go:

Here's a working example https://pwny.emkae.net/#!/?s=html&c=40&l=15&t=5d000000026203000000000000001e1cc86755bb63d868551718ad8cbae957433adc0f6afa4a15a0ffa881ce6495bddea1d0149519ff7acef25a95954195caa0fce29a5c2fb60bd809a73bf7932eecb48a935e5b7e8f5bbaf260ccfa6b0ec93e713479aaaf2c47b7f3e236a0c9b9f60bd7d8177a77d5c247a2ab13d20febc7ca681ac5449cdf2d5ae661cb1eae0e648be0ba0d0d96cdf0b1bc5a02f7438fd2dd420d89ff0210078d46fa16ac1fa4c8c0700995ba20a52d254b430d78d4340103557a62b28d837967acef1d899d1cf877d43abd2ed09e6b5571dcd71b97a4d3ea562eccf8a2d12c1bd8d566a9e675c23c3b759cb3982fb4a23a0d4dd15610cd2463a1a8d6ba3625c697182b7d156ad6bc1be11d53ce2d588438877f3c464f5603001764fbeba1455e829905de5110ff6725b7489385f7e9db8d38e69bd0b718627587463c0936258b769459ddaefbdac70ffc83cd76e37c267629cf6fbad5fdeb81abf95f6822b969127d8090b9c795a011bf361024c1b21c471c3066fcf1e7128cf33307f4a73ca03c236db9ed9a8f57b11e1613a5d9f0f275f512ebbfc39a3dfb1f5ef860eee11b9da394a9a0f05b9c1602fc48f63c716b3bb0104bba5d617cf976a6c567325f72af84fff19a23a7

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kylefox/jquery-modal/issues/209#issuecomment-317369853, or mute the thread https://github.com/notifications/unsubscribe-auth/AIGhFKnFmsjYxtJj4j5_1IxrL24Z2f2Kks5sRGUDgaJpZM4OgljN .

gorillamoe commented 7 years ago

That is not related to this plugin, but anyway, here you go:

<button id=demo_btn1>Inception</button>
<div style="display:none" id=oldschool_w_rapper>
  <form>
    <input type="email" value="" />
  </form>
</div>
<script>
(function(window, document){
  var btnCb = function() {
    $.ajax({url: "dummy.json", success: function(result) {
      var $form = $(oldschool_w_rapper).children().eq(0);
      $form.find('input').eq(0).val(result[0].email);
      $form.modal();
    }});
  };
  demo_btn1.onclick = btnCb;
})(window, document);
</script>

Working example is here

lcsqlpete commented 7 years ago

Thanks, will try it.

On Tue, Jul 25, 2017 at 12:47 AM, Marco Kellershoff < notifications@github.com> wrote:

That is not related to this plugin, but anyway, here you go:

Working example is here https://pwny.emkae.net/#!/?s=html&c=57&l=14&t=5d00000002aa02000000000000001e1cc86755bb63d868551718ad8cbae957433adc0f6afa4a15a0ffa881ce6495bddea1d0149519ff7acef25a95954195caa0fce29a5c2fb60bd809a73bf7932eecb48a935e5b7e8f5bbaf260ccfa6b0ec93e713479aaaf2c47b7f3e236a0c9b9f60bd7d8177a77d5c247a2ab13d20febc7ca681ac5449cdf2d5ae661cb1eae0e648be0ba0d0d96cdf0b1bc5a02f6f70d39f1571bb8d4fb97a99cab739f641ba82baeb84c072f1c914d0cca161d91c06933c9f0988fe53e35d4dba6ed540210ad8fa89072bcfa4dfe7290ce6af20252a87f6c04f944587c5aa354c3116aa44535922079af5e3f30d128c1933751dc23cf7f57e4de34a732fbe3946527ace78563eb0b3494fc04fc5ca6a025569ef903232176ba0478328dc3770062abb06ce1f3c56347a9833e1135db74fbe03e2199dffee5fefede69a8cf0b42412c40e617b858f67b05e2a92aca0b56f7450d17fed85ee1d5845a0f69c82e6f2902c26e8a0651aa9f4e9a9895dfef928925012de9213b479eca5c7415f0bd2287118a3aacf09a026745b795d6db9fff76e62c00

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kylefox/jquery-modal/issues/209#issuecomment-317657825, or mute the thread https://github.com/notifications/unsubscribe-auth/AIGhFNDa8vGFbG86MRJJI785e6hR_BQvks5sRZ19gaJpZM4OgljN .