Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:33:33+00:00 2026-06-01T02:33:33+00:00

I’m trying to get a helloworld type program working with REST CI/jquery. I’ve included

  • 0

I’m trying to get a helloworld type program working with REST CI/jquery. I’ve included my (really rudimentary) REST controller, view file and javascript file and am hoping that the error that has eluded me jumps out at you.

Two issues:

  1. The response I get from the server does not get displayed – the screen gets refreshed instead (I know this is some very basic thing I’ve missed). If I step through the code, I see the display of the result but then, screen gets refreshed. And somehow, I cannot step into my “success” function. Why, oh why?

2.Upon success, I’d like to redirect the user to another url, say, http://www.google.com. Would I do this in the javascript file? or server side?

Thank you in advance for helping me!

[Added after solving the issue: My problem has nothing to do with REST or Codeigniter. A purely javascript problem]
The REST Controller:

<?php
    require APPPATH.'/libraries/REST_Controller.php';

    class Myex extends REST_Controller {
      function contact_post(){
        $result=array();
        $fname=$this->post('fname');
        $lname=$this->post('lname');
        $result['message']="contact_post has your name";
        $result['fname']=$fname."XX";
        $result['lname']=$lname."YY";
        $this->response($result,200);
      }
    }
?>

The view file:

<?php $this->load->view('includes/header')?>
    <div id="input-div"> 
        <form name="cookieform" id="login" method="post">
          First Name: <input type="text" name="fname" id="fname" class="text"/>
          Last Name: <input type="text" name="lname" id="lname" class="text"/>
          <input type="submit" name="submit" value="Submit" id='submit' class="page"/>
        </form>
    </div>
    <div id="resp-div"> 
    response goes here
    </div>
<?php $this->load->view('includes/footer')?>

The javascript file:

function postsuccess(output) {
    $('#soln-div').html(output.message +'for user '+output.fname+' whose last name is '+output.lname).show('slow');
}
function post_contact() {
    $('#submit').click(function(){
        var output;
        var fdata,res;
        var furl=global_siteurl+'/myex/contact';
        var fname=$('#fname').val();
        var lname=$('#lname').val();
        fdata='fname='+fname+'&lname='+lname;
        res=$.ajax({
        url: furl,
        type: 'POST',
        dataType: 'json',
            data:fdata,
            success: function(output) { 
                postsuccess(output); 
          }
        });
    });
}
$(document).ready(function() {
    get_contact();
    post_contact();
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:33:35+00:00Added an answer on June 1, 2026 at 2:33 am
    1. You have called your ajax function upon submission of form you can prevent refreshing of page in 2 ways:
      (a) Use <input type="button" /> instead of submit call your ajax function on this button or
      (b) Use return false; in your success function of ajax request.

    2. You can redirect to any url in javascript using window.top.location = 'url-to-redirect';

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.