Jquery to get php mysql results
SO I have successfully gotten my form to submit but I need to display my comments with each image in a gallery based on the image name attribute which is stored in a db and passed to jquery via javascript variable.
I cannot seem to get the comments to display in the browser and I get no error messages.
here is my jquery code:
-
var curRow = dsCottonClubMain.getCurrentRow();
var curRowNum = curRow['@id'];
var curName = curRow['name'];
var queryString = 'index.php?name=' + curName;
//alert('Image Name is ' + curName);
function showCmnts (){
$.ajax({
type: "POST",
url: "showCommentsPHP.php",
data: queryString,
success: function(data){
$("#showComments").showResponse(responseText, statusText)
},
error: function(){
$("#showComments").p("An Error Occurred");}
});
};
MY JQUERY CODE
-
function getCmnts() {
var options = {
target: '#showComments',
beforeSubmit: showRequest,
success: showResponse,
type: 'post'
};
// bind to the form's submit event
$('#getCommentsForm').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options);
// always return false to prevent standard browser submit and page navigation
return false;
});
};
//// CALLBACKS -- // ---->
// pre-submit callback
function showRequest(formData, jqForm, options) {
// formData is an array; here we use $.param to convert it to a string to display it
// but the form plugin does this for you automatically when it submits the data
var queryString = $.param(formData);
// jqForm is a jQuery object encapsulating the form element. To access the
// DOM element for the form do this:
// var formElement = jqForm[0];
return true;
}
// post-submit callback
function showResponse(responseText, statusText) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
}
here is my php:
-
$cmnt = mysql_query("SELECT imgName,usrName,usrEmail,usrComment,date
FROM comments
WHERE imgName =" . $_POST['name'];);
while($data = mysql_fetch_array($cmnt)
{
$img = $data[0];
$uName = $data[1];
$uEmail = $data[2];
$uComment = $dtat[3];
$uDate = $data[4];
echo "<div>
<ul>
<li>Posted: " . $uDate ."</li>
<li>By: ". $uName ."</li>
</ul>
<p> ". $uComment ."</p>
</div>"
}
?>
Not sure what I have done here but it just doesn't give me anything back from the server.
Tahnx