0

I am using codeigniter where i put the post backend coding under models/add_subscriber.php but the code not being hit. Any idea?

form.onsubmit = function(event) { validate(); if (!isValid) { revalidateOnChange(); return false; } var email = $("#signup_email").val(); dataString = 'email=' + email; $.ajax( { type: "POST", url: '<?php echo base_url()?>models/add_subscriber.php', data: dataString, success: function(response) { alert(response); }, error: function(xhr, textStatus, error) { } }); return; }; 
3
  • You need to call a controller , not a model. It's controllers that are instantiated upon a server request, and they in turn call a model Commented Dec 19, 2013 at 20:43
  • ok.i tried controllers and it didn't got hit too. url: '<?php echo base_url()?>controllers/home/add', Commented Dec 19, 2013 at 20:56
  • 1
    The URL for the controller is <?php echo base_url(); ?>home/add; not the one you specified. Commented Dec 19, 2013 at 20:59

2 Answers 2

1

try to figure out step by step,

  1. Your request is working check in firebug or chrome developer tool net panel may be javascript error there.
  2. hit directly the url see the url is valid view source of the javascript and copy the ajax url and paste it to address bar and see whether your url is valid.
  3. if url is ok and ajax is working and the response isn't 404 than check your controller, htaccess etc.

Suggestion

if you want a URL access to a resource (such as css, js, image), use base_url(), otherwise, site_url() is better. source

Sign up to request clarification or add additional context in comments.

Comments

1

Create a controller in the "controllers" folder... Create a file something like this:

class your_controller extends CI_Controller { function example_function(){ // PUT HERE YOU CODE that is in the models.addsubscriber.php } } 

In your code JS script, put this URL:

url: '<?php echo base_url()?>your_controller/example_function/' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.