publicGenome Posted October 30, 2015 Share Posted October 30, 2015 Hi There, This is my first post in the forum kindly pardon me if I've violated any forum rules. I've a form, enter something, hit submit, data gets inserted into the database using AJAX POST call. I've been trying to pull data from PHP and display, using AJAX GET. But unfortunately, I get complete web page. Data I'm sending/echo-ing is in JSON. I tried exit() in the PHP "select *", but it didn't help. Below are my code snippets: Form code: <form id="randomInsert" action="<?php echo URL;?>dashboard/xhrInsert" method="post"> <input type="text" id="name_form" name="name_text"/> <input type="submit" id="name-submit" /> </form> Model code: public function xhrGetListings(){ $sth=$this->db->prepare('select * from data'); $sth->setFetchMode(PDO::FETCH_ASSOC); $sth->execute(); echo json_encode($sth->fetchAll()) ; // return $sth->fetchAll(); } Java script code: $.get('dashboard/xhrGetListings',function(data){ console.log(data); alert(JSON.stringify(data)); }); //}); $('#randomInsert').submit(function(){ var url=$(this).attr('action'); var data=$(this).serialize(); $.post(url,data, function(o){ }); return false; }); Quote Link to comment https://forums.phpfreaks.com/topic/298942-getting-entire-webpage-in-ajax-get/ Share on other sites More sharing options...
publicGenome Posted November 4, 2015 Author Share Posted November 4, 2015 A gentle bump on this post. Quote Link to comment https://forums.phpfreaks.com/topic/298942-getting-entire-webpage-in-ajax-get/#findComment-1525507 Share on other sites More sharing options...
Ch0cu3r Posted November 5, 2015 Share Posted November 5, 2015 When you say "But unfortunately, I get complete web page." does that mean your are getting HTML/CSS along with your json data or no json data at all? Also can you give information about your php application. Is it completely custom or are you using a specific framework? If its custom how are routing the request for 'dashboard/xhrGetListings'? Quote Link to comment https://forums.phpfreaks.com/topic/298942-getting-entire-webpage-in-ajax-get/#findComment-1525647 Share on other sites More sharing options...
publicGenome Posted November 13, 2015 Author Share Posted November 13, 2015 Hi ch0cu3r, Thanks for your reply. Yes, I was getting response with HTML and CSS code. I was calling my function poorly from bootstrap. I fixed that. Quote Link to comment https://forums.phpfreaks.com/topic/298942-getting-entire-webpage-in-ajax-get/#findComment-1526352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.