I have tried to find a solution, but coming up blank. My page requires a swapout of information when a link is selected. Basicaly you select an item of choice, then the main div is swaped out with a form and data regarding your selection.
I already have a functioning page setup for this, but as it is all in PHP, the page reloads completely each time. This is not good for some selections as there is a full refresh of the link section as well ( which can be quite long depending on member ). So reload time can be a little long on some accounts, that is why I am opting for the jQuery swapout.
This is my jQuery script.
function swapContent(cv) {
$("#input").html('<img src="28.gif"/>').show();
var url = "scripts/run.php";
开发者_如何学编程 $.post(url, {contentVar: cv} ,function(data) {
$("#input").html(data).show();
});
}
PHP is simple "echo" return of value.
if ($contentVar == true) {
echo $resultLoad;
}
$resultLoad; is the completed variable that is created in the PHP script. All looks good and seems to work on most things, but I am having a little problem with the "echo" outputing all its info.
If I add a second "echo", befor or after the if statement ( or even a second inside it as well ), the first echo will always have half the info displayed and the rest display fine.
It is not a timing isue as I have tried timers in jQuery and PHP to allow data completion with no affect.
If you want to see it for yourself, you can go to the test page ( but you need to be a loggedIn member with a YouTube account with uploads in it ) Dont worry.... Free site :)
But if you dont have one, then here is a screen capture for example.
=======================================================================
EDIT:
@Rusty Jeans ( and anyone else ) I have a large script that runs in PHP. In PHP, I have a function that reads a YouTube streem for a given members account. I then pars out the reletive info that is required which is suplied in an SXML format from the YT server. I then do a check to see if I have that particular video already in the system. All this works fine. Problem comes from the last part that writes out a HTML form and displays it.
include_once "dropdown_java.php";
$resultLoad = $dropdown_java.'
<table width="455" border="0">
<tr>
<td>
<p><div class="thumbnail"><a href="' . $href . '\" target="_blank">
<img src="' . $thumb . '" width="120" height="90" /></a></div></p>
<p><b><u>VideoId:</u></b><br /> ' . $vid . '</p>
<p><b><u>Video Title:</u></b><br /> ' . $vidtitle . '</p> <p><b><u>Video Discription:</u></b><br /> ' . $vidDiscript . '</p>
</td>
</tr>
</table>
<form action="php_uploader.php" method="post" enctype="multipart/form-data" name="myform" id="dataInput">
<span class="alignRt"><b><u>Area Of Interest:</u></b><br />
<select name="Area_Of_Interest" size="1" id="Area_Of_Interest"
onchange="setOptions(document.myform.Area_Of_Interest.options[document.myform.Area_Of_Interest.selectedIndex].value);">
'.$first_option_dropdown.'
</select><br /><br />
<span class="alignRt"><b><u>Category:</u></b><br />
<select name="Category" id="Category" size="1">
<option value="" selected="selected"></option>
</select>
</span></p>
<p><span class="alignRt"><b><u>Difficulty:</u></b>
<input name="Difficulty" type="text" class="formFields" id="Difficulty" size="1" maxlength="1" />
<font size="-1" >Difficulty out of 5 [ 1: Easy - 5: Hard ] </font></span>
<p>
</p><font size="-1" >Please supply a zip file with the learning material for the tutorial</p></font>
<font size="2"><b>Choose your file here: </b></font><a href="#" onclick="MM_popupMsg(\'Only .zip format will be uploaded.\rAnything else will be converted to a .zip and be unreadable.\')">
<font size="1" style="cursor: help" color="#00CCFF"><b>(?)</b></font></a>
<input name="zipFile" type="file" class="formFields" id="zipFile" style="border-style: none; color: white; background-color: #000; border-style: solid; border-color: white; border-width: 1px;"/><br /><br />
<br />
<input name="Submit3" type="submit" onclick="MM_validateForm(\'youtube\',\'\',\'R\',\'Video_Title\',\'\',\'R\',\'VideoID\',\'\',\'R\',\'Video_Discription\',\'\',\'R\',\'Area_Of_Interest\',\'\',\'R\',\'Category\',\'\',\'R\',\'Difficulty\',\'\',\'RinRange1:5\');
return document.MM_returnValue" value="Submit Form" /></form>
</p>';
If you notice as well, I have a javascript in the form for the dropdown lists.
For some reason the first table and the "dropdown java" chunck is omited in the first pass of the echo's. I did join them as well as a test, but still NO.
===============================================================
UPDATE :
==========
After some research and playing around, I have found out two things. Firstly, it seems that the javascript in the php is the cause some how. Might be wrong, but does seem that way. ( my untrained eye )
Secondly, I have found that it works on GoogleChroma and FireFox just fine. Only IE is acting up. I am testing on IE8.
I hope that someone can help with this or has had a similar problem in the past that was solved.
Maybe the jQuery is interpreting it incorrectly? Try adding the "html"
type to your $.post()
:
function swapContent (cv) {
$("#input").html('<img src="28.gif"/>').show();
var url = "scripts/run.php";
$.post(url, {contentVar: cv}, function (data) {
$("#input").html(data).show();
}, "html");
}
There is also a shorthand method specifically for what you're doing, .load().
$("#input").load("scripts/run.php?contentVar=" + cv).show();
You'll have to access $_GET['contentVar']
instead of $_POST['contentVar']
in your PHP.
精彩评论