JS / Ajax warning window error

I have a warning window that asks for "Image Download", although it’s $imagenameempty.

Here's the script:

<script>
  function ajax_post1(ca){

    var cat = ca;
    var name = document.getElementById("name").value; 
    var desc = document.getElementById("description").value;
    var key = document.getElementById("keyword").value;
    var image = document.getElementById("image").value; 

    if ($.isEmptyObject(image)) {
      alert('pls upload your image')
    } else {
      alert(' image uploaded ')
    }

    var myData = 'content_ca='+ cat + '&content_desc='+desc+ '&content_key='+key+ '&content_name='+name;//build a post data structure

    jQuery.ajax({
      type: "POST", // HTTP method POST or GET
      url: "uploadsignuppackageresponse.php", //Where to make Ajax calls
      dataType:"text", // Data type, HTML, json etc.
      data:myData, //Form variables
      success:function(response){

      //$("#imagebox").append(response);
      //$("#contentText").val(''); //empty text field on successful
      //alert("haha");

      }, error:function (xhr, ajaxOptions, thrownError){
        alert(thrownError);
      }
    });

  };
</script>

This is the main page:

<?php
  $sql1 = mysql_query ("SELECT * FROM dumimage WHERE email = '$user_signup' AND cat='company' ");
  $row = mysql_fetch_array($sql1);
  $imagename = $row['name'];
?>

Name: 
  <input id="name" type="text"  ></input>
  <input id="image" type="hidden" value="<?php echo $imagename ?> "></input>
Description
  <textarea id="description" rows="7" cols="42"></textarea>
Keywords: 
  <input id="keyword" type="text" placeholder="3 Maximum Keywords" ></input>

<input type="submit"  value="Upload" class="pre" style="float:left; onClick="ajax_post1('company')">   
+4
source share
2 answers

Try this to see if your objects are empty.

if (image.length < 1) {
      alert('pls upload your image')
} else {
      alert(' image uploaded ')
}
0
source

Try replacing this line:

if ($.isEmptyObject(image)) {

With the help of this:

if (image != '') {

You should also fix your php code because you closed the bracket in the wrong place and you are missing a semicolon:

<input id="image" type="hidden" value="<?php echo $imagename;?>"></input>
0
source

Source: https://habr.com/ru/post/1568163/


All Articles