0

I am trying to use jQuery/AJAX to run a PHP file on a server. This PHP simply adds a row with some constants to a database. Here is my code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Submit Application</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
    $.get("http://.../submitApp.php");
}
</script>

</head>

<body>
<form id="form1" name="form1" method="post" action="javascript:doSomething()">
  <p>
    <label for="programName"></label>
    <input type="text" name="programName" id="programName" />
  </p>
  <p>
    <label for="greQuant"></label>
    <input type="text" name="greQuant" id="greQuant" />
  </p>
  <p>
    <label for="greVerbal"></label>
    <input type="text" name="greVerbal" id="greVerbal" />
  </p>
  <p>
    <input type="submit" name="submitApp" id="submitApp" value="Submit" />
  </p>
</form>
</body>
</html>

Upon pressing the submit button on the above form, nothing seems to happen. I should mention I am running this locally via DreamWeaver. I know for a fact that the code is reaching the JavaScript method and that the PHP code is functional. Anyone know what's wrong?

4
  • 1
    try onsubmit='doSomething()' instead of action Commented Sep 25, 2013 at 2:11
  • Would this still help if I told you I knew for a fact that the code is getting to the JS method? Commented Sep 25, 2013 at 2:14
  • really ? or did you just add that line ? lol smh Commented Sep 25, 2013 at 2:17
  • 1
    what do you see in the XHR tab in firefox upon clicking the submit button? is there any successful XHR/Ajax request? Commented Sep 25, 2013 at 2:25

1 Answer 1

1

Use POST instead of GET to do this work.

function doSomething() {
   var programName = $('#programName').val();
   var greQuant = $('#greQuant').val();
   var greVerbal = $('#greVerbal').val();
   $.ajax({
      type: "POST",
      url: "submitApp.php", //URL that you call
      data: { programName: programName, greQuant:greQuant, greVerbal:greVerbal } //var in post: var from js
   }).done(function(msg) {
      alert(msg);//change to something to indicate action
   }
});

and with your php, handle like this

<?php

$programName = $_POST['programName'];
$greQuant = $_POST['greQuant'];
$greVerbal = $_POST['greVerbal'];

//do something important

?>

this is just a simple example, you need apply some security to this php code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.