0

I am completely new to all of this coding.. so I apologies for my ignorance in advance.

I have this jquery function (button) which changes the size of the table of where my Post.php is loaded, (to alternate between portrait and landscape). the function itself works great in changing the size however i am stuck in reloading the post.php page.

 $("#cSize").toggle(
 function () {
 $('#p_CWidth').animate({width:720});
 $('#p_SWidth').animate({width:110});
 }, function() {
     $('#p_CWidth').animate({width:520});
 $('#p_SWidth').animate({width:310});
 });

what i need to add to this code is away of changing the variable p_Type to true or false and reloading the post.php or the div p_Post

 <div id="p_Post">
 <? $p_type = true;
 include 'profile/post.php'; ?>
 </div>

post.php with the above code is loaded fine and i tested it by manually changing p_type to false/true and it loaded ok. But how can i get this automated with the jquery functoin above?

I have tried .load('profile/post.php') however this brings me an error for db access!!

any help is really appreciated AB

UPDATE

I have changed my php file to just a simple php without any link to mysql for testing, and i have tried the suggested code:

var p_type = false;
$("#cSize").toggle(function () {
   $("#p_post").load('profile/post.php',{ 'p_type' : p_type }, function { 
       p_type = !p_type; //toggle the value for automation
});

   $('#p_CWidth').animate({width:720});
   $('#p_SWidth').animate({width:110});

});

and sadly that doesnt seem to work?!!

but with some trial and error i have manged to get change in size working again, and the php reloaded for the first time with the new right variable (p_type), however for some reason the php file only loads once! so it doesnt go back to the normal size with (p_type as true after being set as false)??? here is the code:

   $("#cSize").toggle(
    function () {
  $('#p_CWidth').animate({width:720});
  $('#p_SWidth').animate({width:110});
  $("#p_Post").load('profile/p_post.php',{ p_type : false });
}, function() {
      $('#p_CWidth').animate({width:520});
  $('#p_SWidth').animate({width:310});
  $("#p_Post").load('profile/p_post.php',{ p_type : true });
   });

Thank you again in advance

ps. here is the toggle example i followed http://jsfiddle.net/6FMZY/

2 Answers 2

1

You can add additional data to your jQuery snippet like this

$("#p_post").load('profile/post.php',{ p_type : false });

But since you are trying to automate this, while relaoding

var p_type = false;
$("#p_post").load('profile/post.php',{ 'p_type' : p_type }, function(data) { 
    'p_type' = !p_type; //toggle the value for automation
});

Update:

Here is a simulation of sending the data on toggle

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

6 Comments

i have tried adding the above code: $("#cSize").toggle( function () { $('#p_CWidth').animate({width:720}); $('#p_SWidth').animate({width:110}); var p_type = false; $("#p_Post").load('profile/post.php', {'p_type' : p_type} , function { p_type = !p_type; }); }, function() { $('#p_CWidth').animate({width:520}); $('#p_SWidth').animate({width:310}); var p_type = true; $("#p_Post").load('profile/p_post.php', {'p_type' : p_type} , function { p_type = !p_type; }); }); but that just made the whole thing stop working...
Just forgot to say... I should of said thank you for your reply first ... guess spending all day trying to sort this out is making me go nuts... sorry and thank you again
sorry again... i have also tried to add this $("#p_post").load('profile/post.php',{ p_type : false }); however this reloads the php file but with an MySQL error for access denied
@Belhajio, To solve the mysql error i have to set the php code, as well. But that would a different question so post another one.
Thank you for your help.. I will post a new question regarding the mysql error.
|
0

Soooorted!

I have edited the p_post.php to make it easier by adding get function:

<?
if(isset($_GET['p_type'])){
$p_type=$_GET['p_type'];
}

if($p_type == "normal"){
 // what happen here
} if($p_type == "wide"){
 // what happen here
}
?> 

for the jquery i used:

$("#cSize").toggle(
function () {
   $('#p_CWidth').stop(true).animate({width:720});
   $('#p_SWidth').stop(true).animate({width:110});
   $("#p_Post").load('profile/p_post.php?p_type=wide');
}, function() {
   $('#p_CWidth').stop(true).animate({width:520});
   $('#p_SWidth').stop(true).animate({width:310});
   $("#p_Post").load('profile/p_post.php?p_type=normal');
});

Now its working perfect and just need to sort the denied access issue for php!! Thank you again for the help

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.