A
Anonymous
Guest
Hi Members,
This is my first post to this forum kindly bear with me if I've violated any posting rules.
In my application, I've a form. User enters, and hit submit - data is inserted into table. Insertion is being done using AJAX.
Next I'd like to show the inserted data using AJAX GET function. However, I do not get anything back. Neither alert inside it works.
My form code:
My AJAX code:
Code to pull rows entered:
jQuery JavaScript Library v1.11.3
I can see data is being pulled in my model (JSON encoded), but for some mysterious reason I do not get any alert inside dashboard/xhrGetListings function in java script.
Please help.
This is my first post to this forum kindly bear with me if I've violated any posting rules.
In my application, I've a form. User enters, and hit submit - data is inserted into table. Insertion is being done using AJAX.
Next I'd like to show the inserted data using AJAX GET function. However, I do not get anything back. Neither alert inside it works.
My form code:
Code:
<form id="randomInsert" action="<?php echo URL;?>dashboard/xhrInsert" method="post">
<input type="text" id="name_form" name="name_text"/>
<input type="submit" />
</form>
My AJAX code:
Code:
$(function(){
$.get('dashboard/xhrGetListings',function(o){ //data gets pulled in model
alert("Back here"); // no alert..
},'json');
$('#randomInsert').submit(function(){ //this works
var url=$(this).attr('action');
var data=$(this).serialize();
$.post(url,data, function(o){
});
return false;
});
}
);
Code to pull rows entered:
Code:
public function xhrGetListings(){
$sth=$this->db->prepare('select * from data');
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
echo json_encode($sth->fetchAll()) ;
exit ; //to see if this would help.. this doesn't though
// return $sth->fetchAll();
}
I can see data is being pulled in my model (JSON encoded), but for some mysterious reason I do not get any alert inside dashboard/xhrGetListings function in java script.
Please help.