0

Hi Can anybody tell me what I'm doin wrong here..? I want to post values from the form to the 'some.php' file to insert in the db. The problem is that sometimes the values go in.. sometimes it dosn't.. tried various other options but it doesn't seem to work.. Any help would be appreciated. Thanks in advance :)

Here's the HTML code

<form method="POST" id="Form1" name="Form1">        
     <td>Number :<input name='numbr' type="text" maxlength="10" size="15"></td>
     <td>Amount <input name='amt' type="text" maxlength="4" size="4"></td>
     <td><input id="done" type="submit" value="Done"> | </td>
</form>

Here's the js file

var dataString = $('#Form1').serialize();
    $.ajax({
    type: "POST",
    url: "some.php",
    data: dataString,
    cache: false,
    success: function(){`enter code here`
        alert('Boom!')
    }
});

Ps: it does not alert('Boom') as well.. and im retrieving data in the php file like this..

$num = mysql_real_escape_string($_POST['numbr']);
$amt = mysql_real_escape_string($_POST['amt']);
3
  • You should post the PHP code too. Commented Sep 16, 2011 at 12:58
  • If 'enter code here' is really in your code then that might be the problem. Commented Sep 16, 2011 at 12:59
  • are you getting any javascript errors ? Commented Sep 16, 2011 at 13:22

3 Answers 3

2

Do an alert on dataString to see what it is serialized to. On your serverside, output the same to ensure it is received. On your browser, install tools such as httpwatch or firebug to watch the http traffic.

Finally, "enter code here", is that an example or is it really what is going into your javascript codes?

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

Comments

2

Here is the code that should work for you.

Working demo http://jsfiddle.net/usmanhalalit/2wF6M/ (note here success won't work as some.php is not there, but it sends request)

$(function(){
  var dataString = $('#Form1').serialize();
  $.ajax({ 
    type: "POST",
    url: "some.php",
    data: dataString,
    cache: false,
    success: function(){
            alert('Boom!') 
        } 
  });
});

Comments

0

serialize may be having problems due to malformed html try using this html

<form method="POST" id="Form1" name="Form1">       
    <ul> 
         <li><label>Number :</label><input name='numbr' type="text" maxlength="10" size="15" /></li>
         <li><label>Amount</label> <input name='amt' type="text" maxlength="4" size="4" /></li>
         <li><input id="done" type="submit" value="Done" /></li>
    </ul>
</form>

we also need to see your php

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.