国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Inhaltsverzeichnis
Key Takeaways
wie es funktioniert
herunterladen
Der jQuery -Code - jQuery.js
Der jQuery -Code - ajaxFileUpload.js
Heim Web-Frontend js-Tutorial Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP

Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP

Mar 04, 2025 am 01:09 AM

Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP

Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP UPDATE 18/11/2012: Die neue Version dieses Uploads ist jetzt hier. Auf diese Weise k?nnen Sie Ihren Formularen ein Tool für Datei-/Image -Upload hinzufügen und AJAX die Datei mit PHP speichern und eine Miniaturansicht -Version an den Benutzer zur Anzeige auf dem Formular zurückgeben. Hübsch.

Key Takeaways

  • Verwenden Sie AJAX mit PHP, um den Bild-Upload-Prozess zu optimieren, sodass die Vorschau der Echtzeit-Miniaturansicht ohne Laden der Seite neu laden kann.
  • Stellen Sie eine nahtlose Benutzererfahrung sicher, indem Sie JQuery -Skripte implementieren, mit denen die Datei dynamisch hochgeladen und sofort Miniaturansichten angezeigt werden.
  • Integrieren Sie PHP -Skripte zum Generieren und Rücksenden von Thumbnail -URLs im JSON -Format, was eine einfache Integration und Manipulation auf der Client -Seite erleichtert.
  • Bieten Sie w?hrend des Upload -Prozesses umfassende Fehlerbehandlung und Benutzer -Feedback, um robuste Funktionen und Benutzern zu erhalten.

wie es funktioniert

  1. Benutzer w?hlt eine Datei/ein Bild aus dem Formulareingangsfeld
  2. aus
  3. jQuery sendet eine AJAX -Anforderung mit der Datei/im Bild
  4. PHP erstellt eine Miniaturansichtversion und sendet die URL im JSON -Format
  5. zurück
  6. jQuery zeigt die Miniaturansichtenversion auf dem Formular
  7. an

herunterladen

  • jQuery4U-file-UPLoader-Thumbnail.zip
  • doajaxFileUpload.php
  • ajaxFileUpload.php
  • jQuery.php
  • form-html.php
Download Quell filessee Live Demo

Der jQuery -Code - jQuery.js

<span>/*******************************************************************
</span><span>  JS - PREVIEW IMAGE
</span><span>*******************************************************************/
</span><span>function previewImage(str) {
</span>	<span>//alert(str);
</span>	<span>ajaxFileUpload();
</span><span>}
</span>
<span>function removeImage() {
</span>	<span>//alert("Image Removed");
</span>	<span>$("#imagethumb").html('');
</span>	<span>$("#removebutton").hide();
</span>	<span>$("#supportedfiles").show();
</span>	<span>var tid = $("Input[name=allocatedimagename]").val();
</span>	<span>//remove the temporary image files created by the image
</span>	$<span>.get("/php/deleteblogthumb.php",{thumb_name: tid, type: 'js-blog'}, function(data){
</span>		<span>//alert(data);
</span>	<span>});
</span>
	<span>$("Input[name=allocatedimagename]").val('');
</span>	<span>$("Input[name=blogpic]").val('');
</span><span>}
</span>
<span>function ajaxFileUpload() {
</span>    <span>//starting setting some animation when the ajax starts and completes
</span>    <span>$("#Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP")
</span>    <span>.ajaxStart(function(){
</span>        <span>$(this).show();
</span>    <span>})
</span>    <span>.ajaxComplete(function(){
</span>        <span>$(this).hide();
</span>    <span>});
</span>   
    <span>/*
</span><span>        prepareing ajax file upload
</span><span>        url: the url of script file handling the uploaded files
</span><span>                    fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
</span><span>        dataType: it support json, xml
</span><span>        secureuri:use secure protocol
</span><span>        success: call back function when the ajax complete
</span><span>        error: callback function when the ajax failed
</span><span>       
</span><span>            */
</span>    $<span>.ajaxFileUpload
</span>    <span>(
</span>        <span>{
</span>            <span>url:'doajaxfileupload.php',
</span>            <span>secureuri:false,
</span>            <span>fileElementId:'blogpic',
</span>            <span>dataType: 'json',
</span>            <span>success: function (data<span>, status</span>)
</span>            <span>{
</span>                <span>if(typeof(data.error) != 'undefined')
</span>                <span>{
</span>                    <span>if(data.error != '')
</span>                    <span>{
</span>                        <span>alert(data.error);
</span>                    <span>}else
</span>                    <span>{
</span>                        <span>//alert(data.loc);
</span>                        <span>//show the preview of image
</span>						<span>var imageloc = '<span>Your uploaded image: <samp>'+data.name+'('+data.size+'kb)'+'</samp><br><img src="/static/imghw/default1.png" data-src="'+data.loc+'" class="lazy"    style="max-width:90%"  style="max-width:90%" alt="your uploaded image"></span>';
</span>						<span>$("#imagethumb").html(imageloc); //add
</span>						<span>$("#removebutton").show();
</span>						<span>$("#supportedfiles").hide();
</span>						<span>//save the allocated image name for use with the process signup script
</span>						<span>$("Input[name=allocatedimagename]").val(data.loc);
</span>                    <span>}
</span>                <span>}
</span>            <span>},
</span>            <span>error: function (data<span>, status, e</span>)
</span>            <span>{
</span>                <span>alert(e);
</span>            <span>}
</span>        <span>}
</span>    <span>)
</span>   
    <span>return false;
</span>
<span>}</span>

Der jQuery -Code - ajaxFileUpload.js

jQuery<span>.extend({
</span>
    <span>createUploadIframe: function(id<span>, uri</span>)
</span>	<span>{
</span>			<span>//create frame
</span>            <span>var frameId = 'jUploadFrame' + id;
</span>            
            <span>if(window.<span>ActiveXObject</span>) {
</span>                <span>var io = document.createElement('');
</span>                <span>if(typeof uri== 'boolean'){
</span>                    io<span>.src = 'javascript:false';
</span>                <span>}
</span>                <span>else if(typeof uri== 'string'){
</span>                    io<span>.src = uri;
</span>                <span>}
</span>            <span>}
</span>            <span>else {
</span>                <span>var io = document.createElement('iframe');
</span>                io<span>.id = frameId;
</span>                io<span>.name = frameId;
</span>            <span>}
</span>            io<span>.style.position = 'absolute';
</span>            io<span>.style.top = '-1000px';
</span>            io<span>.style.left = '-1000px';
</span>
            <span>document.body.appendChild(io);
</span>
            <span>return io			
</span>    <span>},
</span>    <span>createUploadForm: function(id<span>, fileElementId</span>)
</span>	<span>{
</span>		<span>//create form	
</span>		<span>var formId = 'jUploadForm' + id;
</span>		<span>var fileId = 'jUploadFile' + id;
</span>		<span>var form = $('');	
</span>		<span>var oldElement = $('#' + fileElementId);
</span>		<span>var newElement = $(oldElement).clone();
</span>		<span>$(oldElement).attr('id', fileId);
</span>		<span>$(oldElement).before(newElement);
</span>		<span>$(oldElement).appendTo(form);
</span>		<span>//set attributes
</span>		<span>$(form).css('position', 'absolute');
</span>		<span>$(form).css('top', '-1200px');
</span>		<span>$(form).css('left', '-1200px');
</span>		<span>$(form).appendTo('body');		
</span>		<span>return form;
</span>    <span>},
</span>
    <span>ajaxFileUpload: function(s) {
</span>        <span>// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout		
</span>        s <span>= jQuery.extend({}, jQuery.ajaxSettings, s);
</span>        <span>var id = new Date().getTime()        
</span>		<span>var form = jQuery.createUploadForm(id, s.fileElementId);
</span>		<span>var io = jQuery.createUploadIframe(id, s.secureuri);
</span>		<span>var frameId = 'jUploadFrame' + id;
</span>		<span>var formId = 'jUploadForm' + id;		
</span>        <span>// Watch for a new set of requests
</span>        <span>if ( s.global && ! jQuery.active++ )
</span>		<span>{
</span>			jQuery<span>.event.trigger( "ajaxStart" );
</span>		<span>}            
</span>        <span>var requestDone = false;
</span>        <span>// Create the request object
</span>        <span>var xml = {}   
</span>        <span>if ( s.global )
</span>            jQuery<span>.event.trigger("ajaxSend", [xml, s]);
</span>        <span>// Wait for a response to come back
</span>        <span>var uploadCallback = function(isTimeout)
</span>		<span>{			
</span>			<span>var io = document.getElementById(frameId);
</span>            <span>try 
</span>			<span>{				
</span>				<span>if(io.contentWindow)
</span>				<span>{
</span>					 xml<span>.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
</span>                	 xml<span>.responseXML = io.contentWindow.document.<span>XMLDocument</span>?io.contentWindow.document.<span>XMLDocument</span>:io.contentWindow.document;
</span>					 
				<span>}else if(io.contentDocument)
</span>				<span>{
</span>					 xml<span>.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
</span>                	xml<span>.responseXML = io.contentDocument.document.<span>XMLDocument</span>?io.contentDocument.document.<span>XMLDocument</span>:io.contentDocument.document;
</span>				<span>}						
</span>            <span>}catch(e)
</span>			<span>{
</span>				jQuery<span>.handleError(s, xml, null, e);
</span>			<span>}
</span>            <span>if ( xml || isTimeout == "timeout") 
</span>			<span>{				
</span>                requestDone <span>= true;
</span>                <span>var status;
</span>                <span>try {
</span>                    status <span>= isTimeout != "timeout" ? "success" : "error";
</span>                    <span>// Make sure that the request was successful or notmodified
</span>                    <span>if ( status != "error" )
</span>					<span>{
</span>                        <span>// process the data (runs the xml through httpData regardless of callback)
</span>                        <span>var data = jQuery.uploadHttpData( xml, s.dataType );    
</span>                        <span>// If a local callback was specified, fire it and pass it the data
</span>                        <span>if ( s.success )
</span>                            s<span>.success( data, status );
</span>    
                        <span>// Fire the global callback
</span>                        <span>if( s.global )
</span>                            jQuery<span>.event.trigger( "ajaxSuccess", [xml, s] );
</span>                    <span>} else
</span>                        jQuery<span>.handleError(s, xml, status);
</span>                <span>} catch(e) 
</span>				<span>{
</span>                    status <span>= "error";
</span>                    jQuery<span>.handleError(s, xml, status, e);
</span>                <span>}
</span>
                <span>// The request was completed
</span>                <span>if( s.global )
</span>                    jQuery<span>.event.trigger( "ajaxComplete", [xml, s] );
</span>
                <span>// Handle the global AJAX counter
</span>                <span>if ( s.global && ! --jQuery.active )
</span>                    jQuery<span>.event.trigger( "ajaxStop" );
</span>
                <span>// Process result
</span>                <span>if ( s.complete )
</span>                    s<span>.complete(xml, status);
</span>
                <span>jQuery(io).unbind()
</span>
                <span>setTimeout(function()
</span>									<span>{	try 
</span>										<span>{
</span>											<span>$(io).remove();
</span>											<span>$(form).remove();	
</span>											
										<span>} catch(e) 
</span>										<span>{
</span>											jQuery<span>.handleError(s, xml, null, e);
</span>										<span>}									
</span>
									<span>}, 100)
</span>
                xml <span>= null
</span>
            <span>}
</span>        <span>}
</span>        <span>// Timeout checker
</span>        <span>if ( s.timeout > 0 ) 
</span>		<span>{
</span>            <span>setTimeout(function(){
</span>                <span>// Check to see if the request is still happening
</span>                <span>if( !requestDone ) uploadCallback( "timeout" );
</span>            <span>}, s.timeout);
</span>        <span>}
</span>        <span>try 
</span>		<span>{
</span>           <span>// var io = $('#' + frameId);
</span>			<span>var form = $('#' + formId);
</span>			<span>$(form).attr('action', s.url);
</span>			<span>$(form).attr('method', 'POST');
</span>			<span>$(form).attr('target', frameId);
</span>            <span>if(form.encoding)
</span>			<span>{
</span>                form<span>.encoding = 'multipart/form-data';				
</span>            <span>}
</span>            <span>else
</span>			<span>{				
</span>                form<span>.enctype = 'multipart/form-data';
</span>            <span>}			
</span>            <span>$(form).submit();
</span>
        <span>} catch(e) 
</span>		<span>{			
</span>            jQuery<span>.handleError(s, xml, null, e);
</span>        <span>}
</span>        <span>if(window.attachEvent){
</span>            <span>document.getElementById(frameId).attachEvent('onload', uploadCallback);
</span>        <span>}
</span>        <span>else{
</span>            <span>document.getElementById(frameId).addEventListener('load', uploadCallback, false);
</span>        <span>} 		
</span>        <span>return {abort: function () {}};	
</span>
    <span>},
</span>
    <span>uploadHttpData: function( r<span>, type</span> ) {
</span>        <span>var data = !type;
</span>        data <span>= type == "xml" || data ? r.responseXML : r.responseText;
</span>        <span>// If the type is "script", eval it in global context
</span>        <span>if ( type == "script" )
</span>            jQuery<span>.globalEval( data );
</span>        <span>// Get the JavaScript object, if JSON is used.
</span>        <span>if ( type == "json" )
</span>            <span>eval( "data = " + data );
</span>        <span>// evaluate scripts within html
</span>        <span>if ( type == "html" )
</span>            <span>jQuery("").html(data).evalScripts();
</span>			<span>//alert($('param', data).each(function(){alert($(this).attr('value'));}));
</span>        <span>return data;
</span>    <span>}
</span><span>})
</span>
<span>The PHP Code – doajaxfileupload.php
</span>$ratio2<span>)	{
</span>          $thumb_w<span>=$new_w;
</span>          $thumb_h<span>=$old_y/$ratio1;
</span>        <span>}
</span>        <span>else	{
</span>          $thumb_h<span>=$new_h;
</span>          $thumb_w<span>=$old_x/$ratio2;
</span>        <span>}
</span>
          <span>// we create a new image with the new dimmensions
</span>        $dst_img<span>=<span>ImageCreateTrueColor</span>($thumb_w,$thumb_h);
</span>
        <span>// resize the big image to the new created one
</span>        <span>imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
</span>
        <span>// output the created image to the file. Now we will have the thumbnail into the file named by $filename
</span>        <span>if(!strcmp("png",$ext))
</span>          <span>imagepng($dst_img,$filename);
</span>        <span>else
</span>          <span>imagejpeg($dst_img,$filename);
</span>
          <span>//destroys source and destination images.
</span>        <span>imagedestroy($dst_img);
</span>        <span>imagedestroy($src_img);
</span>       <span>}
</span>
       <span>// This function reads the extension of the file.
</span>       <span>// It is used to determine if the file is an image by checking the extension.
</span>       <span>function getExtension($str) {
</span>               $i <span>= strrpos($str,".");
</span>               <span>if (!$i) { return ""; }
</span>               $l <span>= strlen($str) - $i;
</span>               $ext <span>= substr($str,$i+1,$l);
</span>               <span>return $ext;
</span>       <span>}
</span>
        <span>//reads the name of the file the user submitted for upZeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP
</span>       $image<span>=$_FILES[$fileElementName]['name'];
</span>
 	<span>// if it is not empty
</span> 	<span>if ($image)
</span> 	<span>{
</span> 		<span>// get the original name of the file from the clients machine
</span> 		$filename <span>= stripslashes($_FILES[$fileElementName]['name']);
</span>
 		<span>// get the extension of the file in a lower case format
</span> 	 	$extension <span>= getExtension($filename);
</span> 		$extension <span>= strtolower($extension);
</span> 		<span>// if it is not a known extension, we will suppose it is an error, print an error message
</span> 		<span>//and will not upload the file, otherwise we continue
</span> 		<span>if (($extension != "jpg")  && ($extension != "jpeg") && ($extension != "png"))
</span> 		<span>{
</span> 			$error <span>.= 'Unknown extension!';
</span> 			$errors<span>=1;
</span> 		<span>}
</span> 		<span>else
</span> 		<span>{
</span> 			<span>// get the size of the image in bytes
</span> 			<span>// $_FILES['image']['tmp_name'] is the temporary filename of the file in which
</span>			<span>//the uploaded file was stored on the server
</span> 			$size<span>=getimagesize($_FILES[$fileElementName]['tmp_name']);
</span> 			$sizekb<span>=filesize($_FILES[$fileElementName]['tmp_name']);
</span>
 			<span>//compare the size with the maxim size we defined and print error if bigger
</span> 			<span>if ($sizekb > MAX_SIZE*1024)
</span> 			<span>{
</span> 				$error <span>.= 'You have exceeded the size limit!';
</span> 				$errors<span>=1;
</span> 			<span>}
</span> 			<span>else {
</span>
              <span>//we will give an unique name, for example the time in unix time format
</span>            $image_name<span>=time().'.'.$extension;
</span>            <span>//the new name will be containing the full path where will be stored (images folder)
</span>            $newname<span>="/images/masters/".$image_name;
</span>            $copied <span>= copy($_FILES[$fileElementName]['tmp_name'], $newname);
</span>            <span>//we verify if the image has been uploaded, and print error instead
</span>            <span>if (!$copied)
</span>            <span>{
</span>              $error <span>.= 'Copy unsuccessfull!';
</span>              $errors<span>=1;
</span>            <span>}
</span>            <span>else
</span>            <span>{
</span>              <span>// the new thumbnail image will be placed in images/thumbs/ folder
</span>              $thumb_name<span>='/images/thumbs/thumb_'.$image_name;
</span>              <span>// call the function that will create the thumbnail. The function will get as parameters
</span>              <span>//the image name, the thumbnail name and the width and height desired for the thumbnail
</span>              $thumb<span>=make_thumb($newname,$thumb_name,40,40);
</span>
              <span>//also add the users pic
</span>              $thumb_name<span>='/images/thumbs/thumb_'.$image_name;
</span>              $thumb<span>=make_thumb($newname,$thumb_name,110,110);
</span>
            <span>}}
</span>        <span>}
</span> 			<span>}
</span>
      <span>//--------- END SECOND SCRIPT --------------------------------------------------------------------
</span>
      <span>//return variables to javascript
</span>			$filename <span>= $_FILES[$fileElementName]['name'];
</span>			$filesize <span>= round(($sizekb/1000), 0);
</span>			$fileloc <span>= $thumb_name;
</span>			<span>//for security reason, we force to remove all uploaded file
</span>			@<span>unlink($_FILES[$fileElementName]);
</span>	<span>}
</span>	$return_JSON <span>= "";
</span>	$return_JSON <span>.= "{";
</span>	$return_JSON <span>.=				"error: '" . $error . "',n";
</span>	$return_JSON <span>.=				"name: '" . $filename . "',n";
</span>	$return_JSON <span>.=				"size: '" . $filesize . "',n";
</span>	$return_JSON <span>.=				"loc: '" . $fileloc . "'n";
</span>	$return_JSON <span>.= "}";
</span>	echo $return_JSON<span>;
</span><span>?>
</span>
<span>The HTML Code
</span><span><label for="blogpic">Blog Thumbnail Picture:</label>
</span>          <span><input type="file" size="23" id="blogpic" name="blogpic" onchange="javascript:previewImage(this.value)">
</span>          <span><div id="preview-image">
              <span><div id="imagethumb"></div>
</span>              <span><input type="text" id="allocatedimagename" name="allocatedimagename">
</span>              <span><div id="Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP" style="visibility:hidden"><img src="/images/Zeigen%20Sie%20Vorschaubild%20des%20Bildes%20hoch%20laden%20Ajax/PHP.gif" alt="Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP" title="Zeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP"></div>
</span>              <span><div id="supportedfiles"><p class="nomargin">Supported file types: jpg, jpeg, png (max 1mb) <br>Your image will be resized to 110 by 110 px (40 by 40 for blog thumbs)</p></div>
</span>
              <span><div id="removebutton"><button id="buttonremove" onclick="javascript:removeImage()"></button></div>
</span>          <span></span>
</div>
</span>        <span>
</span>


<span>Frequently Asked <span>Questions</span> (FAQs) about Thumbnail Image Upload with AJAX/PHP
</span>


<span>How can I handle multiple image uploads using AJAX/PHP? Handling multiple image uploads using AJAX/PHP is quite similar to handling a single image upload. <span>The</span> main difference is that you need to loop through the array of files in the $_FILES superglobal. <span>For</span> each file, you can perform the same validation and upload process as you would for a single file. <span>Remember</span> to adjust your HTML form to allow multiple file selection by adding the ‘multiple’ attribute to your input tag.  <span>How</span> can I display a progress bar during the image upload? To display a progress bar during the image upload, you can use the ‘progress’ event of the XMLHttpRequest object. <span>This</span> event is triggered periodically during the upload process, and you can use it to calculate the percentage of the upload that has been completed and update your progress bar accordingly.  <span>How</span> can I resize the uploaded image before saving it to the server? Resizing the uploaded image before saving it to the server can be done using PHP’s GD library or ImageMagick. <span>These</span> libraries provide functions to create a new image with the desired dimensions and copy the uploaded image into it, effectively resizing it. <span>Remember</span> to adjust the quality of the image to avoid losing too much detail during the resizing process.  <span>How</span> can I handle errors during the image upload process? Handling errors during the image upload process is crucial to provide a good user experience. <span>You</span> can check for errors by inspecting the ‘error’ property of the file in the $_FILES superglobal. <span>This</span> property will be 0 if no error occurred, and a different value otherwise. <span>You</span> can then use a switch statement to handle each possible error code and provide a meaningful error message to the user.  <span>How</span> can I restrict the types of images that can be uploaded? Restricting the types of images that can be uploaded can be done by checking the ‘type’ property of the file in the $_FILES superglobal. <span>This</span> property contains the MIME type of the file, which you can compare with the allowed types (e.g., ‘image/jpeg’, ‘image/png’, etc.). <span>If</span> the file’s type is not in the list of allowed types, you can reject the upload and provide an error message to the user.  <span>How</span> can I secure my image upload script against attacks? Securing your image upload script against attacks is crucial to prevent unauthorized access to your server. <span>You</span> can do this by validating the uploaded file thoroughly, checking its size, type, and content, and rejecting any file that doesn’t meet your criteria. <span>You</span> should also rename the uploaded file to a random name to prevent attackers from overwriting existing files or executing arbitrary code on your server.  <span>How</span> can I limit the size of the uploaded images? Limiting the size of the uploaded images can be done by checking the ‘size’ property of the file in the $_FILES superglobal. <span>This</span> property contains the size of the file in bytes, which you can compare with your maximum allowed size. <span>If</span> the file’s size is larger than the allowed size, you can reject the upload and provide an error message to the user.  <span>How</span> can I store the uploaded images in a database? Storing the uploaded images in a database can be done by saving the path to the image in a database table. <span>You</span> should not store the image data itself in the database, as this can quickly fill up your database and degrade its performance. <span>Instead</span>, save the image to a directory on your server and store the path to this file in your database.  <span>How</span> can I display the uploaded images on my website? Displaying the uploaded images on your website can be done by retrieving the paths to the images from your database and using them in the ‘src’ attribute of ‘img’ tags. <span>Remember</span> to sanitize the paths before outputting them to prevent cross-site scripting (XSS) attacks.  <span>How</span> can I delete uploaded images from the server? Deleting uploaded images from the server can be done using the ‘unlink’ function in PHP. <span>This</span> function deletes a file from the server. <span>You</span> should also remove the path to the image from your database to keep it in sync with the file system.  
</span>

Das obige ist der detaillierte Inhalt vonZeigen Sie Vorschaubild des Bildes hoch laden Ajax/PHP. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Erkl?rung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Hei?e Themen

PHP-Tutorial
1502
276
Wie stelle ich eine HTTP -Anforderung in node.js? Wie stelle ich eine HTTP -Anforderung in node.js? Jul 13, 2025 am 02:18 AM

Es gibt drei g?ngige M?glichkeiten, HTTP-Anforderungen in Node.js zu initiieren: Verwenden Sie integrierte Module, Axios und Knotenfetch. 1. Verwenden Sie das integrierte HTTP/HTTPS-Modul ohne Abh?ngigkeiten, das für grundlegende Szenarien geeignet ist, jedoch eine manuelle Verarbeitung von Datengen?hten und Fehlerüberwachung erfordert, z. 2.Axios ist eine auf Versprechen basierende Bibliothek von Drittanbietern. Es verfügt über eine kurze Syntax und leistungsstarke Funktionen, unterstützt Async/Auseait, automatische JSON -Konvertierung, Interceptor usw. Es wird empfohlen, asynchrone Anforderungsvorg?nge zu vereinfachen. 3.Node-Fetch bietet einen Stil ?hnlich dem Browser-Abruf, basierend auf Versprechen und einfacher Syntax

JavaScript -Datentypen: Primitive VS -Referenz JavaScript -Datentypen: Primitive VS -Referenz Jul 13, 2025 am 02:43 AM

JavaScript -Datentypen sind in primitive Typen und Referenztypen unterteilt. Zu den primitiven Typen geh?ren String, Anzahl, Boolesche, Null, undefiniertes und Symbol. Die Werte sind unver?nderlich und Kopien werden bei der Zuweisung von Werten kopiert, sodass sie sich nicht gegenseitig beeinflussen. Referenztypen wie Objekte, Arrays und Funktionen speichern Speicheradressen, und Variablen, die auf dasselbe Objekt zeigen, wirkt sich gegenseitig aus. Typeof und Instanz k?nnen verwendet werden, um die Typen zu bestimmen, aber auf die historischen Probleme der TypeOfnull zu achten. Das Verst?ndnis dieser beiden Arten von Unterschieden kann dazu beitragen, einen stabileren und zuverl?ssigeren Code zu schreiben.

JavaScript Time Object, jemand erstellt eine EACTEXE, schnellere Website auf Google Chrome usw. JavaScript Time Object, jemand erstellt eine EACTEXE, schnellere Website auf Google Chrome usw. Jul 08, 2025 pm 02:27 PM

Hallo, JavaScript -Entwickler! Willkommen in den JavaScript -Nachrichten dieser Woche! Diese Woche konzentrieren wir uns auf: Oracas Markenstreit mit Deno, neue JavaScript -Zeitobjekte werden von Browsern, Google Chrome -Updates und einigen leistungsstarken Entwickler -Tools unterstützt. Fangen wir an! Der Markenstreit von Oracle mit dem Versuch von Deno Oracle, ein "JavaScript" -Marke zu registrieren, hat Kontroversen verursacht. Ryan Dahl, der Sch?pfer von Node.js und Deno, hat eine Petition zur Absage der Marke eingereicht, und er glaubt, dass JavaScript ein offener Standard ist und nicht von Oracle verwendet werden sollte

Handlingversprechen: Verkettung, Fehlerbehandlung und Versprechenkombinatoren in JavaScript Handlingversprechen: Verkettung, Fehlerbehandlung und Versprechenkombinatoren in JavaScript Jul 08, 2025 am 02:40 AM

Versprechen ist der Kernmechanismus für den Umgang mit asynchronen Operationen in JavaScript. Das Verst?ndnis von Kettenanrufen, Fehlerbehebung und Kombination ist der Schlüssel zum Beherrschen ihrer Anwendungen. 1. Der Kettenaufruf gibt ein neues Versprechen durch .then () zurück, um asynchrone Prozessverkampferung zu realisieren. Jeder. Dann () erh?lt das vorherige Ergebnis und kann einen Wert oder ein Versprechen zurückgeben; 2. Die Fehlerbehandlung sollte .Catch () verwenden, um Ausnahmen zu fangen, um stille Ausf?lle zu vermeiden, und den Standardwert im Fang zurückgeben, um den Prozess fortzusetzen. 3. Combinatoren wie Promise.All () (erfolgreich erfolgreich erfolgreich nach allen Erfolg), Versprechen.Race () (Die erste Fertigstellung wird zurückgegeben) und Versprechen.Allsettled () (Warten auf alle Fertigstellungen)

Was ist die Cache -API und wie wird sie bei Dienstangestellten verwendet? Was ist die Cache -API und wie wird sie bei Dienstangestellten verwendet? Jul 08, 2025 am 02:43 AM

Cacheapi ist ein Tool, das der Browser zur Cache -Netzwerkanfragen bereitstellt, das h?ufig in Verbindung mit dem Servicearbeiter verwendet wird, um die Leistung der Website und die Offline -Erfahrung zu verbessern. 1. Es erm?glicht Entwicklern, Ressourcen wie Skripte, Stilbl?tter, Bilder usw. Zu speichern; 2. Es kann die Cache -Antworten entsprechend den Anfragen übereinstimmen. 3. Es unterstützt das L?schen bestimmter Caches oder das L?schen des gesamten Cache. 4.. Es kann Cache -Priorit?ts- oder Netzwerkpriorit?tsstrategien durch Servicearbeiter implementieren, die sich auf Fetch -Ereignisse anh?ren. 5. Es wird h?ufig für die Offline -Unterstützung verwendet, die wiederholte Zugriffsgeschwindigkeit, die Vorspannungs -Schlüsselressourcen und den Inhalt des Hintergrundaktualisierungss beschleunigen. 6. Wenn Sie es verwenden, müssen Sie auf die Cache -Versionskontrolle, Speicherbeschr?nkungen und den Unterschied zum HTTP -Caching -Mechanismus achten.

JS Roundup: Ein tiefes Eintauchen in die JavaScript -Ereignisschleife JS Roundup: Ein tiefes Eintauchen in die JavaScript -Ereignisschleife Jul 08, 2025 am 02:24 AM

Die Ereignisschleife von JavaScript verwaltet asynchrone Vorg?nge, indem sie Call -Stapel, Webapis und Task -Warteschlangen koordinieren. 1. Der Anrufstack führt synchronen Code aus, und wenn er auf asynchrone Aufgaben begegnet, wird er zur Verarbeitung an Webapi übergeben. 2. Nachdem das Webapi die Aufgabe im Hintergrund abgeschlossen hat, wird der Rückruf in die entsprechende Warteschlange (Makroaufgabe oder Micro -Aufgabe) eingebaut. 3. Die Ereignisschleife prüft, ob der Anrufstapel leer ist. Wenn es leer ist, wird der Rückruf aus der Warteschlange herausgenommen und zur Ausführung in den Anrufstapel geschoben. V. 5. Das Verst?ndnis der Ereignisschleife hilft zu vermeiden, den Haupt -Thread zu blockieren und die Codeausführungsreihenfolge zu optimieren.

Ereignis verstehen und in JavaScript DOM -Ereignissen sprudeln und erfassen Ereignis verstehen und in JavaScript DOM -Ereignissen sprudeln und erfassen Jul 08, 2025 am 02:36 AM

Ereignisblasen verbreiten sich vom Zielelement nach au?en zum Vorfahrknoten aus, w?hrend Ereignisfassungen sich von der ?u?eren Schicht nach innen zum Zielelement ausbreiten. 1. Ereignisblasen: Nach dem Klicken auf das untergeordnete Element l?st das Ereignis den H?rer des übergeordneten Elements nach oben aus. Nach dem Klicken auf die Schaltfl?che gibt es beispielsweise zuerst die untergeordnete und dann entzündete Eltern aus. 2. Ereigniserfassung: Stellen Sie den dritten Parameter auf True ein, so dass der H?rer in der Erfassungsstufe ausgeführt wird, z. B. das Ausl?sen des Capture -Listeners des übergeordneten Elements, bevor Sie auf die Schaltfl?che klicken. 3. Praktische Verwendungszwecke umfassen ein einheitliches Management von Ereignissen für Kinderelemente, Vorverarbeitung und Leistungsoptimierung von Abfangen. V.

Eine JS-Zusammenfassung von Funktionen h?herer Ordnung jenseits der Karte und des Filters Eine JS-Zusammenfassung von Funktionen h?herer Ordnung jenseits der Karte und des Filters Jul 10, 2025 am 11:41 AM

In JavaScript -Arrays gibt es zus?tzlich zu MAP und Filter andere leistungsstarke und selten verwendete Methoden. 1. Reduzierung kann nicht nur summieren, sondern auch z?hlen, gruppen, flach Arrays ab und bauen neue Strukturen auf. 2. FindingIndex werden verwendet, um einzelne Elemente oder Indizes zu finden. 3. Einige und alles werden verwendet, um festzustellen, ob Bedingungen bestehen oder sich alle treffen. 4. SORT kann sortiert werden, wechselt aber das ursprüngliche Array. 5. Achten Sie darauf, das Array zu kopieren, wenn Sie es verwenden, um Nebenwirkungen zu vermeiden. Diese Methoden machen den Code pr?gnanter und effizienter.

See all articles