Note that there are some explanatory texts on larger screens.

plurals
  1. POError in Jquery and Ajax
    primarykey
    data
    text
    <p>I write the code for uploading image in local machine in ajax and jquery. And if condition is not executed. </p> <p>Here is the fnUploadImage script.</p> <pre><code>function fnUploadPhoto() { var image = $("#txtUploadImage").val(); var objUploadImage = new Object(); objUploadImage.ImageName = image; objUploadImage.UserID = &lt;?php echo $_SESSION['UserId']; ?&gt; $.ajax({ type:"POST", url:"db.php?UploadImage", data: {data:objUploadImage}, dataType:"json", async:false, success: function(response) { alert(response.ErrorMessage); if(response.IsError) $("#errorUploadPhoto")[0].innerHTML = response.ErrorMessage; else $("#errorUploadPhoto")[0].innerHTML = response.SuccessMessage; }, error:function(response) { alert("Error: " + response.ErrorMessage); } }); } </code></pre> <p>And this function calls the db.php UploadImage function which is as follows:</p> <pre><code>function UploadImage($data) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["txtUploadImage"]); $extension = end($temp); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) &amp;&amp; in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] &gt; 0) { die(json_encode(array("IsError" =&gt; true, "ErrorMessage" =&gt; "Error"))); //echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br&gt;"; json_encode(array("IsError" =&gt; true, "ErrorMessage" =&gt; "Return Code: " . $_FILES["file"]["error"])); } else { if (file_exists("profile_images/" . $_FILES["file"]["txtUploadImage"])) { //echo $_FILES["file"]["name"] . " already exists. "; json_encode(array("IsError" =&gt; true, "ErrorMessage" =&gt; "Filename already exists.")); } else { if($_FILES["file"]["size"]/1024 &lt; 20) { move_uploaded_file($_FILES["file"]["tmp_name"], "profile_images/" . $_FILES["file"]["txtUploadImage"]); //echo "Stored in: " . "profile_images/" . $_FILES["file"]["name"]; json_encode(array("IsError" =&gt; false, "SuccessMessage" =&gt; "Image uploaded successfully.")); } else { json_encode(array("IsError" =&gt; true, "ErrorMessage" =&gt; "Minimum image size is 20 kb.")); } } } } else { //echo "Invalid file."; json_encode(array("IsError" =&gt; true, "ErrorMessage" =&gt; "Invalid file.")); } } </code></pre> <p>When i run this script it shows in me the Error called undefined. Please help me to solve this. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload