6

I made a jQuery model.

Am trying to populate data using AJAX inside that model.

I am getting an id and using that I want to populate data using AJAX.

How should I call AJAX on click event?

Is there any other event when the model is opened or loaded?

The model is just the showing and hiding of div.

3
  • Which modal plugin? Jquery-ui modal? if so that does have an open event. Need clarification Commented Aug 31, 2010 at 15:28
  • Also..what does getting an id mean. Where are you getting it, from what, in what event - show us some code to give context...read Jon Skeets advice on how to ask a question msmvps.com/blogs/jon_skeet/archive/2010/08/29/… Commented Aug 31, 2010 at 15:34
  • $('a.pop').click(function() { var popID = $(this).attr('rel'); //Get Popup Name var popURL = $(this).attr('href'); //Get Popup href to define $.get("content.php", { ref:id},function(data){ alert("Data Loaded: "+data ); } ); i want to call that ajax file on this click event. how to do Commented Aug 31, 2010 at 15:55

2 Answers 2

10

Simply using:

JS:

$(document).ready(function(){
  $('a.pop').click(function() { 
    var popID = $(this).attr('rel');
    $.get('content.php', { ref:popID }, function(data) {
       $(popID+'Container').html(data);
       $(popID).dialog();
       alert('Load was performed.');
    });
    return false; // prevent default
  });
});

HTML:

<div id="example" class="flora" title="This is my title">
    I'm in a dialog!
    <div id="exampleContainer"></div>
</div>
<a href="#" id="clickingEvent" class="pop" rel="example">click to launch</a>

It is not tested, but as I see it, it should work...

Sign up to request clarification or add additional context in comments.

2 Comments

yes its working... i am new to jquery .. now its getting betetr. am using .get. btw wats the difference in jquery using get and post...? php get post i know. can i get variables of a form using post with out submiting using jqueryposy?? asking foolishly!!! am using get and its working now.
The GET and the POST, are the same in JQUERY and PHP, as it is independent from any language, it's part of the http protocol. Please see this link: w3.org/Protocols/rfc2616/rfc2616-sec9.html
4

You almost have it, you need to prevent the default action which is to follow the href in the link, so add either event.preventDefault() or return false, like this:

$('a.pop').click(function(e) {                     //add e param
  var popID = $(this).attr('rel'),
      popURL = $(this).attr('href');
  $.get("content.php", { ref:id}, function(data) { //did you mean popID here?
    alert("Data Loaded: "+data ); 
  });
  e.preventDefault(); //or return false;           //prevent default action
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.