troubleshooting Question

JQuery if question

Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland asked on
HTMLAJAXjQuery
7 Comments2 Solutions105 ViewsLast Modified:
Hello All,

I have a page that loads an iframe which contains the following script -

<html>
<head>
<link href="/css/desktop.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body style="overflow:hidden; width:498px; height:139px;">
<form action="" method="post" name="DeleteCV" class="fancyform" id="DeleteCV">
  <h3>Delete CV</h3>
  <div class="notify">Deleting your CV will permanently remove it from the CV database, please confirm that you want to permanently remove your CV</div>
  <input name="Delete" type="submit" class="cancelbutton" id="DeleteCVSubmit" form="DeleteCV" value="Delete" />
  <input name="Cancel" type="button" onClick="javascript:parent.jQuery.fancybox.close();" class="closefb" id="DeleteCVCancel" form="DeleteCV" value="Cancel" />
  <input name="CVID" type="hidden" id="CVID" value="<%= Request("ID") %>" form="DeleteCV">
</form>
</body>
</html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script>
  $("#DeleteCV").submit(function(e){
      e.preventDefault();
    $.ajax({
		type: "POST",
        url: "/test4.asp",
        data:$(this).serialize(),
		success:function(result){
          if(result==1){
			window.parent.jQuery.fancybox.close();
			 window.parent.location.reload();
          }else {
	      $('#DeleteCVError').html('<p>ErrorMessage here</p>');
          $('#DeleteCVError').fadeIn('slow');
          }
  	  }});
  });
</script>

You can see that the Jquery is postingthe form data to test4.asp. the code on test4,asp is

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
1
</body>
</html>

so the result will always be 1

This part of the original script is not working -

          if(result==1){
			window.parent.jQuery.fancybox.close();
			 window.parent.location.reload();
          }else {
	      $('#DeleteCVError').html('<p>ErrorMessage here</p>');
          $('#DeleteCVError').fadeIn('slow');
          }
If I substitute the jQuery above to just read -

  $("#DeleteCV").submit(function(e){
			window.parent.jQuery.fancybox.close();
			 window.parent.location.reload();
  });

After the form is submitted the iframe closes and the original window reloads, so the issue must be with the if statement...

Any help appreciated.

Thank you
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros