Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2013, 11:50 PM   PM User | #1
gilgimech
New Coder

 
Join Date: Mar 2010
Posts: 58
Thanks: 10
Thanked 3 Times in 3 Posts
gilgimech is an unknown quantity at this point
Get an html page using AJAX

So, I've been trying to get this to work all day. I make a button for the WordPress TinyMCE. I followed this tutorial.

http://www.garyc40.com/2010/03/how-t...user-friendly/.

This works great, but I want to clean it up by loading the HTML from another page instead of having it in the javascript.

here's the code I'm using.

Code:
jQuery(function($){
// this is the code I want to load from another file 
var form = jQuery('<div id="mygallery-form">\
  <table id="mygallery-table" class="form-table">\
    <tr>\
      <th><label for="href">Href</label></th>\
      <td><input type="text" id="codepen-href" name="href" value=""/><br />\
      <small>the codepen href</small></td>\
    </tr>\
    <tr>\
      <th><label for="mygallery-columns">Username</label></th>\
      <td><input type="text" id="codepen-user" name="user" value=""/><br />\
      <small>the codepen username</small></td>\
    </tr>\
    <tr>\
      <th><label for="mygallery-columns">Type</label></th>\
      <td><input type="text" id="codepen-type" name="type" value=""/><br />\
      <small>the codepen type</small></td>\
    </tr>\
  </table>\
  <p class="submit">\
    <input type="button" id="mygallery-submit" class="button-primary" value="Insert Gallery" name="submit" />\
  </p>\
</div>');

var table = form.find('table');
form.appendTo('body').hide();

form.find('#mygallery-submit').click(function(){
// Do other Stuff
});
})();
Now, I've never really got a good grasp on AJAX. I've tried every example I've found, but none of them seem to load the file.

I've been spending way too much time just getting this to work, so any help would be appriciated.
gilgimech is offline   Reply With Quote
Old 01-20-2013, 01:09 AM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
give this a try.

Code:
jQuery(function($){
// this is the code I want to load from another file 
var form = jQuery.get('/url/of/otherpage.htm #mygallery-table');

form.appendTo('body').hide();

jQuery.('#mygallery-submit').click(function(){
// Do other Stuff
});
})();
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:07 AM.


Advertisement
Log in to turn off these ads.