<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ajax Archives - AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</title>
	<atom:link href="https://atcodex.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>https://atcodex.com/tag/ajax/</link>
	<description>Achieve financial success without sacrificing well-being! AtCodex provides actionable strategies for managing money, time, and personal growth—all in one place.</description>
	<lastBuildDate>Sat, 28 Aug 2021 17:15:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://atcodex.com/wp-content/uploads/2020/05/cropped-New-Project-1-32x32.png</url>
	<title>Ajax Archives - AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</title>
	<link>https://atcodex.com/tag/ajax/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>jQuery ajax image upload in PHP with preview</title>
		<link>https://atcodex.com/php/jquery-ajax-image-upload-in-php-with-preview/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Fri, 31 Jul 2020 19:54:37 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ajax]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=579</guid>

					<description><![CDATA[<p>In PHP it is very easy to upload files on the server with the help of the move_uploaded_file()&#160;method. But in that, you have to load the page again and again &#8230; </p>
<p>The post <a href="https://atcodex.com/php/jquery-ajax-image-upload-in-php-with-preview/">jQuery ajax image upload in PHP with preview</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In PHP it is very easy to upload files on the server with the help of the <em><strong>move_uploaded_file()&nbsp;</strong></em>method. But in that, you have to load the page again and again if you need to upload more images. Nowadays we know that speed plays a very important role in a web application, user skips and gets irritates if the page reloads every time when we do some activity on the website.</p>



<p class="wp-block-paragraph">AJAX is popular because we don&#8217;t need to reload the page in getting done something.  We are now going to discuss <strong><em>how we can upload an image using ajax and PHP with preview</em></strong>.</p>



<p class="wp-block-paragraph">When we use AJAX in the right way, it will improve the user experience. In this post, we will let you know how you can upload image using AJAX and can show preview of image without the page refresh.</p>



<h2 class="wp-block-heading">Image Upload HTML</h2>



<p class="wp-block-paragraph">This is the HTML code to upload the file and display the uploaded image preview. When users click on the Upload button, ajax will upload the file to the folder and fetch it to display on <strong><em>id=&#8221;img&#8221;</em></strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="wpcustom" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">  &lt;div class="container">
            &lt;form method="post" action="" enctype="multipart/form-data" id="myform">
                &lt;div class='preview'>
                    &lt;img src="" id="img" width="100" height="100">
                &lt;/div>
                &lt;div >
                    &lt;input type="file" id="file" name="file" />
                    &lt;input type="button" class="button" value="Upload" id="file_upload">
                &lt;/div>
            &lt;/form>
        &lt;/div></pre>



<h2 class="wp-block-heading">CSS </h2>



<p class="wp-block-paragraph">CSS code to design the above HTML form. We just added this CSS to improve the form view. Its just optional you can skip this part.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="css" data-enlighter-theme="wpcustom" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">.container{
   margin: 0 auto;
   border: 0px solid black;
   width: 50%;
   height: 250px;
   border-radius: 3px;
   background-color: ghostwhite;
   text-align: center;
}
/* Preview */
.preview{
   width: 100px;
   height: 100px;
   border: 1px solid black;
   margin: 0 auto;
   background: white;
}

.preview img{
   display: none;
}
/* Button */
.button{
   border: 0px;
   background-color: deepskyblue;
   color: white;
   padding: 5px 15px;
   margin-left: 10px;
}</pre>



<h2 class="wp-block-heading">PHP file to upload the image</h2>



<p class="wp-block-paragraph">PHP file upload script. You can check the image type before uploading them on the server. if the image gets uploaded, it shows the path of the image otherwise if there is any problem in image upload it will show you 0.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="wpcustom" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/* Getting file name */
$filename = $_FILES['file']['name'];

/* Location */
$location = "fileUpload/".$filename;
$uploadOk = 1;
$imageFileType = pathinfo($location,PATHINFO_EXTENSION);

/* Valid Extensions */
$valid_extensions = array("jpg","jpeg","png");
/* Check file extension */
if( !in_array(strtolower($imageFileType),$valid_extensions) ) {
   $uploadOk = 0;
}

if($uploadOk == 0){
   echo 0;
}else{
   /* Upload file */
   if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){
      echo $location;
   }else{
      echo 0;
   }
}</pre>



<h2 class="wp-block-heading">Uploading Image and Showing Preview using jQuery AJAX</h2>



<p class="wp-block-paragraph">This script contains a jQuery which sends the file to the fileUpload.php. if it gets response 0 from  PHP file it means the file did not get upload, on other than 0 status means the file has been uploaded and then it shows the uploaded image in <strong><em>.preview img</em></strong> class.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="wpcustom" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">  	 $(document).ready(function(){
                    $("#file_upload").click(function(){
                        var fd = new FormData();
                        var files = $('#file')[0].files[0];
                        fd.append('file',files);
                        $.ajax({
                            url: 'fileUpload.php',
                            type: 'post',
                            data: fd,
                            contentType: false,
                            processData: false,
                            success: function(response){
                                if(response != 0){
                                    $("#img").attr("src",response); 
                                    $(".preview img").show(); // Display image 
                                }else{
                                    alert('file not uploaded');
                                }
                            },
                        });
                    });
            });</pre>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link">Output</a></div>
</div>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="jQuery ajax image upload in PHP with preview" width="735" height="413" src="https://www.youtube.com/embed/zF7MXXaY7gk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link" href="https://atcodex.com/wp-content/uploads/2020/07/jQuery-ajax-image-upload-in-PHP-with-preview.zip">Download Source Code</a></div>
</div>
<p>The post <a href="https://atcodex.com/php/jquery-ajax-image-upload-in-php-with-preview/">jQuery ajax image upload in PHP with preview</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>jQuery Back to Top Smooth scroll</title>
		<link>https://atcodex.com/jquery/jquery-back-to-top-smooth-scroll/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Fri, 24 Jul 2020 04:08:14 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Ajax]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=509</guid>

					<description><![CDATA[<p>If you have large content, multiple sections, and topics on your website, then going from bottom to top becomes a bit boring work on the website page. You might have &#8230; </p>
<p>The post <a href="https://atcodex.com/jquery/jquery-back-to-top-smooth-scroll/">jQuery Back to Top Smooth scroll</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">If you have large content, multiple sections, and topics on your website, then going from bottom to top becomes a bit boring work on the website page. You might have observed  &#8220;Back To Top&#8221; button on many websites,  it is used when the page becomes very lengthy. </p>



<p class="wp-block-paragraph">In this tutorial, you will see how you can apply Smooth scrolling effect and allow users to click on back to top button to instantly go on top of the website page. You can also implement this scroll function to a particular section on the website.</p>



<p class="wp-block-paragraph">The following is an HTML code in which we have an anchor tag, which defines the section where we will go after clicking on the scroll button.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;body>
&lt;a name="top" class="top">&lt;/a> 
&lt;!--- your page content goes here -->
&lt;!-- back to top button -->
&lt;a id="goTop" class="btn btn-primary">Back to top&lt;/a>
&lt;/body></pre>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Add Ajax library in scroll back to top</h2>



<p class="wp-block-paragraph">Add the following library in code, which will execute the  jQuery functions.</p>



<pre class="wp-block-code"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">&lt;/script></code></pre>



<h2 class="wp-block-heading">jQuery code for Back to Top Smooth scroll </h2>



<p class="wp-block-paragraph">With <strong>jQuery&nbsp;<em>animate()</em></strong>&nbsp;method, we can easily scroll user back to the top of the page.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;script type='text/javascript'>
$('#goTop').on('click', function(e){
    $("html, body").animate({scrollTop: $(".top").offset().top}, 500);
});
&lt;/script></pre>



<p class="wp-block-paragraph">This is a very simple code to perform jQuery bottom to Top Smooth scroll.  This can also be used to scroll to a particular div section, you just need to pass the <strong>className </strong>in<strong> animate</strong> function. </p>



<p class="wp-block-paragraph">For example, you can use any other <strong>className </strong>than <strong>top </strong>and just place that <strong>className</strong> somewhere in your same website page.</p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link">Output</a></div>
</div>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Add Ajax library in scroll back to top" width="735" height="413" src="https://www.youtube.com/embed/9-FqVKXO5d8?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button"><a class="wp-block-button__link" href="https://atcodex.com/wp-content/uploads/2020/07/jQuery-bottom-to-Top-Smooth-scroll.zip">Download Source Code</a></div>
</div>
<p>The post <a href="https://atcodex.com/jquery/jquery-back-to-top-smooth-scroll/">jQuery Back to Top Smooth scroll</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
