search
HomeBackend DevelopmentPHP Tutorial急!!php页面加载不完全的问题,在线等

PHP

RT,同一个页面多次刷新,有时候正常,有时候只显示一半,有时候则完全空白
完全的页面

一半


本机调试的时候没有遇到此问题,这是在外网发布的时候发生的。下拉框中的内容是用fopen打开了一个.tab文件然后读取出来的,然后通过循环转成数组,又通过循环给js数组赋值,循环为1000。
设置了set_time_limit(60*60*10)依然无效。。。
跪求指导,谢谢。。。附上部分代码
common.php<?phppublic static function readTabFile($fileName)		{			if (!file_exists($fileName)) 			{ 				die("<b>404 File not found!</b>"); 			} 			$handle = fopen($fileName, 'rb');			$contents = fread($handle, filesize ($fileName));						//iconv("UTF-8","GBK", $contents);						if(ord($contents) == 0xEF)			{				$contents = substr($contents, 4);			}			$rows = explode("\r\n", $contents);			fclose($handle);			$ret;			$colNames = null;			for($i = 0; $i < count($rows); $i++)			{				$row = $rows[$i];				if(!empty($row) && $row != "" && substr($row, 0, 1) != "#")				{					$col = explode("\t", $row);					if(empty($colNames) || $colNames == null)						$colNames = $col;					else					{						$item;						$itemId = (int)$col[0];						if(empty($itemId))						{							die("...");						}						for($j = 0; $j < count($col); $j++)						{							$value = $col[$j];														$item[$colNames[$j]] = $value;						}						$ret[$itemId] = $item;					}				}			}			return $ret;					}?>test.php<?php    $dir = "../goods.tab";    $table = Common::readTabFile($dir);?><script>	var goodsTb = new Array();	<?php			foreach($table as $key => $value)		{			echo "goodsTb[".$value["id"]."]=\"".iconv("GBK","UTF-8", $value["sz_name"])."\";";		}	?>	function checkNum(i)	{		var sle_obj = document.getElementById('valueType' + i);		var index = sle_obj.selectedIndex;		var valueType = sle_obj.options[index].value;		var num_obj = document.getElementById('count' + i);		if(valueType == -1)		{			alert('请选择道具类型!');		}		if(num_obj.value > 500)			num_obj.value = 500;	}		var i = 1;	function addFile()	{		var dv = document.getElementById("dvFiles");		var selectObj = document.createElement("select");		selectObj.name = "valueType";		selectObj.id = "valueType" + i;				var sg = document.createTextNode("选择道具 ");		dv.appendChild(sg);		//创建select选项卡		var myOption = document.createElement("option");		myOption.setAttribute("value","-1");		myOption.appendChild(document.createTextNode("无"));		selectObj.appendChild(myOption);		for (var key in goodsTb)		{			var op = document.createElement("option");			op.setAttribute("value", key);			op.appendChild(document.createTextNode(goodsTb[key]));			selectObj.appendChild(op);		}		dv.appendChild(selectObj);....

回复讨论(解决方案)

跪求啊|!!

在线等,呜呜呜呜

管管啊

有时候正常大致可认为代码没问题
完全空白是什么意思?整个页面没一个字?
这多数是网络的问题,和代码没太大关系,除非是你的程序算法太复杂导致在浏览器超时范围内都没有响应

就是一个字都没有,空白。。。
算法也不复杂吧。。。就2个1000的循环而已,代码我也贴出来了。。。
但是肯定是跟网络有关,本地调试都是正常的。。。

空白的原因是因为js里面有个循环,执行js到一半就停止了。。。求方案

空白的原因是因为js里面有个循环,执行js到一半就停止了。。。求方案

可能是js性能问题.

强烈建议用php做循环.比如使用smarty模板,将数组传给显示模板,在里边循环 然后将循环得到的html返回或者输出前台

不要用js循环了


空白的原因是因为js里面有个循环,执行js到一半就停止了。。。求方案

可能是js性能问题.

强烈建议用php做循环.比如使用smarty模板,将数组传给显示模板,在里边循环 然后将循环得到的html返回或者输出前台

不要用js循环了
对js不是很懂- -,但是从ff页面执行源码来看,确实是前段的代码没执行完,php拿出来的数组是正确的,就是在输出js的时候停止了。
没有了解过smarty模板,请问js有解决办法吗

换了中方法,直接用php来输出js也不行。。。感觉老是输出不完全。。。

还有一种可能就是服务器的内存大小限制会有这个影响。



空白的原因是因为js里面有个循环,执行js到一半就停止了。。。求方案

可能是js性能问题.

强烈建议用php做循环.比如使用smarty模板,将数组传给显示模板,在里边循环 然后将循环得到的html返回或者输出前台

不要用js循环了
对js不是很懂- -,但是从ff页面执行源码来看,确实是前段的代码没执行完,php拿出来的数组是正确的,就是在输出js的时候停止了。
没有了解过smarty模板,请问js有解决办法吗


我觉得JS肯定有解决和优化的办法
不过我这里提不出来
我只能建议用PHP来做循环.
如果不懂smarty也没关系 就直接在php里循环 ,用echo来拼出html

为啥非得用js来循环和组合呢

echo $str;	foreach($table as $key => $value)	{		echo 'var op = document.createElement(\"option\");';		echo 'op.setAttribute(\"value\", "'.$value["id"].'");';		echo 'op.appendChild(document.createTextNode("'.iconv("GBK","UTF-8", $value["sz_name"]).'"));';		echo 'selectObj.appendChild(op)';	}	?>

用php来输出Html还是不行。。。。。。。。。。。

汗  你这个用php来输出了一堆js语句....

用PHP直接输出html不行吗.......

大概看了下你的页面最多就是几个有关联的select列表   可能还有ajax去后台取数据   php输出html+js提交查询和选择 完全可以实现    何必每一行都是js代码呢

大概看了下你的页面最多就是几个有关联的select列表   可能还有ajax去后台取数据   php输出html+js提交查询和选择 完全可以实现    何必每一行都是js代码呢
第一个下拉框就是php直接输出的html的,但是有个添加按钮,每点一次都会产生一个新的下拉框。。。。目前添加按钮用的Js实现的


大概看了下你的页面最多就是几个有关联的select列表   可能还有ajax去后台取数据   php输出html+js提交查询和选择 完全可以实现    何必每一行都是js代码呢
第一个下拉框就是php直接输出的html的,但是有个添加按钮,每点一次都会产生一个新的下拉框。。。。目前添加按钮用的Js实现的

点添加又出现一个选择道具物品的下拉框对吗?
和上一个有区别吗?
没有区别就直接将其html插入到上一个下拉单所在的div下方就可以了 

假设第一个下拉框的class=abc,下拉框和后边的输入框在同一个div下
$(".abc").parent().after($(".abc").parent().html());
jquery一句话就实现了

怎么说呢业务细节越细我这边就没法说更多了因为不了解

其实我的意思归根结底就是完全没必要使用复杂的js循环导致页面都显示不完   很多方法可以实现的

好吧,用jquery真的很简单- -
请问 $(".abc").after($(".abc").html()); 可以修改后面赋值内容的id跟name么

你是不是用了什么第三方的模板插件呐,一般引起这问题是因为模板内部缓存功能

好吧,用jquery真的很简单- -
请问 $(".abc").after($(".abc").html()); 可以修改后面赋值内容的id跟name么

当然可以  这是另一个问题

看你的这个select列表的结构和你js文件的写法了

比如你给每一项定义一个自定义属性比如说叫val="id1234"

然后当你选择某一项时  用js获取选择项的这个val和中间的text描述

然后存入后边的input的value中  (用jquery选择器会很方便)

这是js比较简单的应用了.

你是不是用了什么第三方的模板插件呐,一般引起这问题是因为模板内部缓存功能
什么插件都没用。。。


好吧,用jquery真的很简单- -
请问 $(".abc").after($(".abc").html()); 可以修改后面赋值内容的id跟name么

当然可以  这是另一个问题

看你的这个select列表的结构和你js文件的写法了

比如你给每一项定义一个自定义属性比如说叫val="id1234"

然后当你选择某一项时  用js获取选择项的这个val和中间的text描述

然后存入后边的input的value中  (用jquery选择器会很方便)

这是js比较简单的应用了.
jquery没有用过,只是参考文档能了解些语法。。。
我最早贴的图,就是我选择了物品后,需要填写数量,就是一个select跟一个text,
点击添加后,$(".abc").after($(".abc").html())这种方法,会导致select,text的id跟原来的一样,我想区分开来,比如用个变量i控制,每添加一个i就加1.。。
另外我想添加的项后面可以跟个删除按钮,点击删除可以删除本项,麻烦给个代码示例参考下,谢谢- -



好吧,用jquery真的很简单- -
请问 $(".abc").after($(".abc").html()); 可以修改后面赋值内容的id跟name么

当然可以  这是另一个问题

看你的这个select列表的结构和你js文件的写法了

比如你给每一项定义一个自定义属性比如说叫val="id1234"

然后当你选择某一项时  用js获取选择项的这个val和中间的text描述

然后存入后边的input的value中  (用jquery选择器会很方便)

这是js比较简单的应用了.
jquery没有用过,只是参考文档能了解些语法。。。
我最早贴的图,就是我选择了物品后,需要填写数量,就是一个select跟一个text,
点击添加后,$(".abc").after($(".abc").html())这种方法,会导致select,text的id跟原来的一样,我想区分开来,比如用个变量i控制,每添加一个i就加1.。。
另外我想添加的项后面可以跟个删除按钮,点击删除可以删除本项,麻烦给个代码示例参考下,谢谢- -

抱歉才到家.
写了个简单的demo,只有增加和删除DIV的  选择后写入值的可以去网上搜下相关文章

<!doctype html><html lang="cn"><head>	<meta charset="UTF-8">	<title>Document</title>	<meta name="Keywords" content="" />	<meta name="Description" content="" />	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>	<script type="text/javascript">		function addDiv(){			var lastHtml = $(".abc:last").clone();									var item_id = $(".abc:last select").attr("id");			var input_id = $(".abc:last input").attr("id");			var new_item_id = "item_" + (parseInt(item_id.substr(5))+1);			var new_input_id = "item_num_" + (parseInt(input_id.substr(9))+1);			lastHtml.children("select").attr("name",new_item_id);			lastHtml.children("select").attr("id",new_item_id);			lastHtml.children("input").attr("name",new_input_id);			lastHtml.children("input").attr("id",new_input_id);			$(".abc:last").after("<div class='abc'>"+lastHtml.html()+"</div>");		}		function delDiv(obj){			var i = $(".abc").length;			if (i>1)			{				$(obj).parent(".abc").remove();			}else{				alert("至少选择一项");			}		}	</script></head><body>	<div><!--以后换成form-->		<div class="abc">			<select name="item_1" id="item_1" >				<option value="0">无</option>				<option value="1">剑气火灵幻影</option>				<option value="2">神武至尊怒火</option>				<option value="3">鬼舞玄冰法杖</option>			</select>			数量			<input type="text" name="item_num_1" id="item_num_1" value="" />			<a href="javascript:void(0)" onclick="delDiv(this)">删除</a>		</div>		<button onClick = "addDiv()">添加</button>	</div></body></html>


欢迎继续交流啊




好吧,用jquery真的很简单- -
请问 $(".abc").after($(".abc").html()); 可以修改后面赋值内容的id跟name么

当然可以  这是另一个问题

看你的这个select列表的结构和你js文件的写法了

比如你给每一项定义一个自定义属性比如说叫val="id1234"

然后当你选择某一项时  用js获取选择项的这个val和中间的text描述

然后存入后边的input的value中  (用jquery选择器会很方便)

这是js比较简单的应用了.
jquery没有用过,只是参考文档能了解些语法。。。
我最早贴的图,就是我选择了物品后,需要填写数量,就是一个select跟一个text,
点击添加后,$(".abc").after($(".abc").html())这种方法,会导致select,text的id跟原来的一样,我想区分开来,比如用个变量i控制,每添加一个i就加1.。。
另外我想添加的项后面可以跟个删除按钮,点击删除可以删除本项,麻烦给个代码示例参考下,谢谢- -

抱歉才到家.
写了个简单的demo,只有增加和删除DIV的  选择后写入值的可以去网上搜下相关文章

<!doctype html><html lang="cn"><head>	<meta charset="UTF-8">	<title>Document</title>	<meta name="Keywords" content="" />	<meta name="Description" content="" />	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>	<script type="text/javascript">		function addDiv(){			var lastHtml = $(".abc:last").clone();									var item_id = $(".abc:last select").attr("id");			var input_id = $(".abc:last input").attr("id");			var new_item_id = "item_" + (parseInt(item_id.substr(5))+1);			var new_input_id = "item_num_" + (parseInt(input_id.substr(9))+1);			lastHtml.children("select").attr("name",new_item_id);			lastHtml.children("select").attr("id",new_item_id);			lastHtml.children("input").attr("name",new_input_id);			lastHtml.children("input").attr("id",new_input_id);			$(".abc:last").after("<div class='abc'>"+lastHtml.html()+"</div>");		}		function delDiv(obj){			var i = $(".abc").length;			if (i>1)			{				$(obj).parent(".abc").remove();			}else{				alert("至少选择一项");			}		}	</script></head><body>	<div><!--以后换成form-->		<div class="abc">			<select name="item_1" id="item_1" >				<option value="0">无</option>				<option value="1">剑气火灵幻影</option>				<option value="2">神武至尊怒火</option>				<option value="3">鬼舞玄冰法杖</option>			</select>			数量			<input type="text" name="item_num_1" id="item_num_1" value="" />			<a href="javascript:void(0)" onclick="delDiv(this)">删除</a>		</div>		<button onClick = "addDiv()">添加</button>	</div></body></html>


欢迎继续交流啊 非常感谢,结贴!
交个朋友- -

都是新手 多交流

给你个小思路 看能帮到你不!

test.php<?php    $dir = "../goods.tab";    $table = Common::readTabFile($dir);    foreach($table as $key => $value)    {      echo "<option value='{$value["id"]}'>".iconv("GBK","UTF-8", $value["sz_name"])."</option>";   	}?>test.html //加载jquery<select id="tools" name="tools[]"></select><a href="javascript:addTools();"></a><script>function autoTools(){	var i=$("#tools").length-1;$.get("test.php",function(data){$("#tools:eq("+i+")").html(data);});}function addTools(){	$("#tools").after("<select id='tools' name='tools[]'></select>").autoTools();}autoTools();</script>





好吧,用jquery真的很简单- -
请问 $(".abc").after($(".abc").html()); 可以修改后面赋值内容的id跟name么

当然可以  这是另一个问题

看你的这个select列表的结构和你js文件的写法了

比如你给每一项定义一个自定义属性比如说叫val="id1234"

然后当你选择某一项时  用js获取选择项的这个val和中间的text描述

然后存入后边的input的value中  (用jquery选择器会很方便)

这是js比较简单的应用了.
jquery没有用过,只是参考文档能了解些语法。。。
我最早贴的图,就是我选择了物品后,需要填写数量,就是一个select跟一个text,
点击添加后,$(".abc").after($(".abc").html())这种方法,会导致select,text的id跟原来的一样,我想区分开来,比如用个变量i控制,每添加一个i就加1.。。
另外我想添加的项后面可以跟个删除按钮,点击删除可以删除本项,麻烦给个代码示例参考下,谢谢- -

抱歉才到家.
写了个简单的demo,只有增加和删除DIV的  选择后写入值的可以去网上搜下相关文章

<!doctype html><html lang="cn"><head>	<meta charset="UTF-8">	<title>Document</title>	<meta name="Keywords" content="" />	<meta name="Description" content="" />	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>	<script type="text/javascript">		function addDiv(){			var lastHtml = $(".abc:last").clone();									var item_id = $(".abc:last select").attr("id");			var input_id = $(".abc:last input").attr("id");			var new_item_id = "item_" + (parseInt(item_id.substr(5))+1);			var new_input_id = "item_num_" + (parseInt(input_id.substr(9))+1);			lastHtml.children("select").attr("name",new_item_id);			lastHtml.children("select").attr("id",new_item_id);			lastHtml.children("input").attr("name",new_input_id);			lastHtml.children("input").attr("id",new_input_id);			$(".abc:last").after("<div class='abc'>"+lastHtml.html()+"</div>");		}		function delDiv(obj){			var i = $(".abc").length;			if (i>1)			{				$(obj).parent(".abc").remove();			}else{				alert("至少选择一项");			}		}	</script></head><body>	<div><!--以后换成form-->		<div class="abc">			<select name="item_1" id="item_1" >				<option value="0">无</option>				<option value="1">剑气火灵幻影</option>				<option value="2">神武至尊怒火</option>				<option value="3">鬼舞玄冰法杖</option>			</select>			数量			<input type="text" name="item_num_1" id="item_num_1" value="" />			<a href="javascript:void(0)" onclick="delDiv(this)">删除</a>		</div>		<button onClick = "addDiv()">添加</button>	</div></body></html>


欢迎继续交流啊 非常感谢,结贴!
交个朋友- - 哥们在吗?问个问题



大概看了下你的页面最多就是几个有关联的select列表   可能还有ajax去后台取数据   php输出html+js提交查询和选择 完全可以实现    何必每一行都是js代码呢
第一个下拉框就是php直接输出的html的,但是有个添加按钮,每点一次都会产生一个新的下拉框。。。。目前添加按钮用的Js实现的

点添加又出现一个选择道具物品的下拉框对吗?
和上一个有区别吗?
没有区别就直接将其html插入到上一个下拉单所在的div下方就可以了 

假设第一个下拉框的class=abc,下拉框和后边的输入框在同一个div下
$(".abc").parent().after($(".abc").parent().html());
jquery一句话就实现了

怎么说呢业务细节越细我这边就没法说更多了因为不了解

其实我的意思归根结底就是完全没必要使用复杂的js循环导致页面都显示不完   很多方法可以实现的 。。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!