/    Sign up×
Community /Pin to ProfileBookmark

$.post callback data is empty

I have the following in the header if index.php:

[CODE] <script type=”text/javascript” src=”/jquery/jqueryui/js/jquery-1.4.2.min.js”></script>
<script type=”text/javascript” src=”/jquery/jqueryui/js/jquery-ui-1.8.6.custom.min.js”></script>
<script type=”text/javascript” src=”/jquery/jqueryui/development-bundle/ui/jquery.ui.tabs.js”></script>
<script>
$(document).ready(function(){
$(function() {
$( “#tabs” ).tabs();
});
$(“#submit”).click(function(){
var post = $(‘#myForm’).serialize();
$.post(“functions.php”, post, function(data) {
alert(data);
});
});
});
</script>[/CODE]

The relevant body of index.php is:

[QUOTE]

<form action=”” method=”post” enctype=”multipart/form-data” name=”myForm” id=”myForm”>
<label for=”keyword”>Keyword</label>
<input type=”text” name=”keyword” id=”keyword” />
<input type=”submit” name=”submit” id=”submit” value=”Submit” />
</form>

[/QUOTE]

Functions.php has the following:

[QUOTE]

<?php require_once(‘../Connections/cms.php’); ?>
<?php
$myFile = “testFile.txt”;
$fh = fopen($myFile, ‘w’);

// And then the code to run a query with the keyword and print results in a table[/QUOTE]

When I refresh index.php and click on ‘Submit’, it DOES create testFile.txt – meaning it is correctly referring to functions.php, but the alert is empty.

I then delete testFile.txt and click on ‘Submit’ without refreshing, and this time, it does NOT create testFile.txt – and hence, my guess is that it is not calling on functions.php, and of course, alert is empty as usual.

What I want to do is this:
I want to be able to click on the Submit button – without refreshing the page – and return data from functions.php and display it within a div tag on index.php

What am I doing wrong to get an empty alert?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @markjohnson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...