Jump to content

Recommended Posts

Worked great thanks..

 

So with the get method.. I think I have got the following code correct?.. but I can figure out how to access it via a link method?

 

<script type="text/javascript">

$(document).ready(function(){
	$("#clickme").click(function () {
		$("#content").html('Retrieving...');

		$.ajax({
		type:"GET", 
  			data:{ "fname":"12345","lname":"test" }, 
		url: "jqueryresponce.php", 
  			success: function(msg){
		$("#content").html(msg)
		 }
		}
		); 
            				
	});
});

</script>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1375400
Share on other sites

jQuery provides a simplified method for making GET requests; jQuery.get(). Have a look through the documentation. I would personally wrap the functionality inside an object or a couple of functions, and re-use it for every link. With a simple selector you can match each anchor and hijack the normal behaviour.

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1375592
Share on other sites

Yea and from my understading the code below should work..

 

<script type="text/javascript">

$(document).ready(function(){
	$("#clickme").click(function () {
		$("#content").html('Retrieving...');

		$.ajax({
			type:"GET", 
  					data:{ "data1":"12345","data2":"test" }, 
				url: "jqueryresponce.php", 
  				success: function(msg){
				$("#content").html(msg)
		 	}

		}); 
            				
	});
});

</script>

 

<div id="content"> </div>

 

In the page jqueryresponce.php, I have echoed out the get variables but noting loads in the div..

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1375615
Share on other sites

Okay, you need to be a little bit more proactive in a) explaining what you actually want, b) being our eyes as far as what is actually happening. 

 

Do you see your div update with that 'Retrieving...' message?

 

In firebug there is a Net tab. Do you see a request being made to your script when you click the button?

 

If so, does the request show your data?

 

Don't just tell us "It doesn't work," tell us what you DO see happening.

 

 

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1375632
Share on other sites

I dont know how to explain it any better..

 

Another attempt:

 

$("#clickme").click(function(){
	$("#content").html('Retrieving...');
		var url = $(this).attr('href');
	$.get(url, function(response){
	$("#content").html(response);
},'text');
});

 

Link I beleave should work to access above function?:

 

<a href="jqueryget.php?pid=$pid" id="clickme" onclick="#content">Show Details</a>

 

Problem:

 

The entire page reloads, instead of just the div area.. <div id="content"> </div>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1375662
Share on other sites

It would appear you cant u run a jquery function from within the div you are loading it into?

 

Example

 

This works..

 

   <input id="email" type="text" value="" />
   <input id="password" type="text" value="" />
   <input type="button" id="clickme" value="submit" />

    <div id="content"></div>    

<script type="text/javascript">
   $("#clickme").click(function(){
   $("#content").html('<img src="./loading.gif">');
      var data = {email: $('#email').val(), password: $('#password').val()};
   $.post("jqueryget.php", data, function(response){
   $("#content").html(response);
   },'text');
});
</script>  

 

This doesnt work..

 

<div id="content">

      <input id="email" type="text" value="" />
   <input id="password" type="text" value="" />
   <input type="button" id="clickme" value="submit" />

</div>

<script type="text/javascript">
   $("#clickme").click(function(){
   $("#content").html('<img src="./loading.gif">');
      var data = {email: $('#email').val(), password: $('#password').val()};
   $.post("jqueryget.php", data, function(response){
   $("#content").html(response);
   },'text');
});
</script>  

 

I am wanting the login process complete within the div tag id #content, not by placing the form outside of it?

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376256
Share on other sites

So i think the anwer to the above question is the .live() function.. this seems to work great for GET data, but using POST no data seems to arrive after being submited..

 

Here is what I have now:

 

<!-- Div to load content in -->
<div id="content"> </div>

<!-- To populate the #content div when page first loads -->
<script type="text/javascript">

$('#content').load('jqueryresult.php'); 

</script>

<!-- The query to process and pass on the form data -->
<script type="text/javascript">

$("#clickme").live('click',function(){
      $("#content").html('Retrieving...');
           var data = {data1: $('#data1').val(),data2: $('#data2').val(),data3: $('#data3').val()};
      $.post("jqueryresult.php", data, function(response){
      $("#content").html(response);
      },'text');
});

</script>

 

jqueryresult.php layout:

 

<input id="data1" type="text" value="" />
<input id="data2" type="text" value="" />
<input type="button" id="clickme" value="Submit" />
<hr />


<?php

echo ''.$_POST['data1'].' -- '.$_POST['data2'].'';

?>

 

What am I missing for the variables not to be captured? If I place the button and fields outside the #content div it works fine..

 

Maybe

 

<script type="text/javascript">

$('#content').load('jqueryresult.php'); 

</script>

 

Maybe the above cancelling it out again?

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376265
Share on other sites

The moment you click the #clickme button, this line is fired:

 

$("#content").html('Retrieving...');

 

That removes all the content within #content, and replaces it with a text node. That means the form and buttons cease to exist any more, which is why you can't access them.

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376275
Share on other sites

Hmm strugling to put this together.. It doesnt seem to do it when using get method..

 

I thought that  $("#content").html('Retrieving...'); is just a loading screen while it processes the request.. assuming that it would still grab the posted variables and reload the div with the new data..

 

How should it be so I can have the entire script within the #content div without having to place the form outside the div?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376278
Share on other sites

I thought that  $("#content").html('Retrieving...'); is just a loading screen while it processes the request..

 

Well that's what you get in-effect, but really you're just setting the HTML of #content to "Retrieving..." Essentially to:

 

<div id="content">Retrieving...</div>

 

So forms, inputs and all other elements are lost. To make it work you can simply capture the data before you set the HTML (i.e. switch around the lines). Although it may make more sense from a usability perspective just to move the form out of #content.

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376279
Share on other sites

The form in this case is for login.. I really need it in the same div..

 

Basically the page called into the div: jqueryresult.php holds the php code to check against the email and password, relaod the form if match fails or set session data and show member panel..

 

If I shift the form to another div it will stay visable after successful login..

 

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376281
Share on other sites

By switch around do you mean:

 

<script type="text/javascript">
   $("#clickme").click(function(){

         var data = {email: $('#email').val(), password: $('#password').val()};

   $("#content").html('<img src="./loading.gif">');

   $.post("jqueryget.php", data, function(response){
   $("#content").html(response);
   },'text');
});

 

?

 

Is it possible that upon successful login I could clear the div holding the login form?

Link to comment
https://forums.phpfreaks.com/topic/268011-jquery/#findComment-1376287
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.