Note that there are some explanatory texts on larger screens.

plurals
  1. POForms failed to submit
    text
    copied!<p>I have a form which I want to show the response in <code>div</code> via AJAX. Here is the form image from <code>funds_transfer.php</code>.</p> <p><img src="https://i.stack.imgur.com/u3TtZ.png" alt="enter image description here"></p> <p>I test it with manual <code>method=post</code> and submit with the form and it works nicely. Here is the partial PHP code from <code>funds_transfer_backend.php</code>:</p> <pre><code> $index_num = $_POST['index_num']; $to_account_num = $_POST['recipient']; $amount = $_POST['amount']; if ($amount == '' || $to_account_num == '' || $index_num == -1){ echo "Please complete the form!"; $response = -1; } else { // other code goes here.. $display = array('response' =&gt; $response); // for ajax response later echo json_encode($display); </code></pre> <p>PHP gave me this output: </p> <pre><code>Please complete the form!{"response":-1} </code></pre> <p><br> Now I want to implement it with AJAX and it's currently not working. Here is my current no working html + jQuery code:</p> <pre><code>&lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function update() { var two = $('#index_num').val(); var three = $('#recipient_box').val(); var five = $('#amount_box').val(); $.post("funds_transfer_backend.php", { index_num : two, recipient : three, amount : five },function(data){ if (data.response==-1) { $('#stage').show().html("Please complete the form!"); } $('#stage').delay(2000).fadeOut(); },"json"); } &lt;/script&gt; //other code goes here.. &lt;p&gt;Transfer your funds to other account &lt;script type="text/javascript"&gt; // Pre populated array of data var myData = new Array(); &lt;?php $sql="SELECT * FROM `account` WHERE client_id='$id'"; $result=mysqli_query($conn, $sql); while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "myData.push('".$row['funds']."');"; $result_array[] = $row['id']; } ?&gt; &lt;/script&gt; &lt;form id="example" name="example"&gt; Select your account&lt;select id="selector" name="index_num" style="margin-left: 10px;"&gt; &lt;option value="-1"&gt;Account Number&lt;/option&gt; &lt;?php //echo $result_array[0]; $num = count($result_array) - 1; $i=0; while($i&lt;=$num) { echo "&lt;option value=\"$i\"&gt;$result_array[$i]&lt;/option&gt;"; $i++; } ?&gt; &lt;/select&gt; &lt;br /&gt; Funds : RM &lt;input type="text" id="populateme" name="funds" disabled/&gt;&lt;br&gt; Recipient Account Number &lt;input type="text" id="recipient_box" name="recipient" /&gt; &lt;br&gt; Amount : RM &lt;input type="text" id="amount_box" name="amount"/&gt;&lt;br&gt; &lt;input type="button" value="Submit" onclick="update();"&gt; &lt;input type="reset" value="Reset"&gt; &lt;/form&gt; &lt;div id="stage" style="background-color:#FF6666; padding-left:20px; color: white;"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; document.example.selector.onchange = updateText; function updateText() { var obj_sel = document.example.selector; document.example.populateme.value = myData[obj_sel.value]; } &lt;/script&gt; &lt;/p&gt; </code></pre> <p>The SQL query above will fetch data from db and populated it in the <code>select box</code> and <code>disabled text box</code>. No problem with that it's currently works nicely.</p> <p>The problem is there's no response in <code>div id="stage</code> after submit and validation <code>data.response==-1</code> . I'm not sure what's the problem here probably the form didn't submit at all. Please help and thanks in advance.</p>
 

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