0

I want to make link action to controller in codeigniter after get response from ajax. I need a variable from ajax response to put in the link to controller, and then in controller, I need to operate update process. I've tried using php link but it doesn't work. Error shows The URI you submitted has disallowed characters.

Here's the script

          $.ajax({
              type : "GET",
              url  : "<?php echo admin_url().'leads/data_status'; ?>",
              success : function(response2){
                 var data2 = JSON.parse(response2);
                 var html = '';
                 var a;

                 for(a=0; a<data2.length; a++)
                 {

                    html += '<tr>'+
                                '<td>'+data2[a].name+'</td>'+
                                '<td>'+data2[a].company+'</td>'+
                                '<td><a href="<?php echo admin_url().'leads/trash/status='?>'+data2[a].status+'&id='+data2[a].id+'">Back</a></td>'+
                             '</tr>';

                 }

              }
           })

Here's controller script

public function trash(){
    $id=$this->input->get('id');
    $status=$this->input->get('status');

    $data = array(
        'status' => $status,
        'last_status' => null
    );

    $this->db->where('id',$id);
    $this->db->update(db_prefix() . 'leads', $data);

    redirect('admin');
}

Do you know how to fix the code ?

Thanks

6
  • Codeigniter: URI you submitted has disallowed characters Commented Feb 6, 2020 at 11:08
  • Hi @N'Bayramberdiyev, I've tried it before, but it's still show same error Commented Feb 6, 2020 at 11:20
  • Then try to encode URL parameters using encodeURIComponent(). Decode them before use in your controller. And where do you output html variable in your AJAX call? Commented Feb 6, 2020 at 11:26
  • you can check in your response which url you are getting and then try to run in your browser and then check what is the issue in your url... Commented Feb 6, 2020 at 11:31
  • Can you try this way assign a variable before ajax function var adminurl = '<?php echo admin_url()?>'; pass the variable inside ajax like this url:adminurl + "leads/data_status", Commented Feb 6, 2020 at 12:00

1 Answer 1

1

There are concatination issues in your code, I have udpated the string can you please try with this one

html += '<tr>'+
    '<td>'+data2[a].name+'</td>'+
    '<td>'+data2[a].company+'</td>'+
    '<td><a href="<?php echo admin_url();?>leads/trash/status='+data2[a].status+'&id='+data2[a].id+'">Back</a></td>'+
'</tr>';

or with storing url in a variable like

url = "<?php echo admin_url();?>leads/trash/";
url += 'status='+data2[a].status;
url += '&id='+data2[a].id;

html += '<tr>'+
    '<td>'+data2[a].name+'</td>'+
    '<td>'+data2[a].company+'</td>'+
    '<td><a href="'+encodeURIComponent(url)+'">Back</a></td>'+
'</tr>';

don't forget to use urldecode in php if you use encodeURIComponent

$id=urldecode($this->input->get('id'));
$status=urldecode($this->input->get('status'));
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Prateik, thank you, I've found where's the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.