Welcome Guest, Not a member yet? Register   Sign In
Error: The URI you submitted has disallowed characters
#1

[eluser]Krystian[/eluser]
Hi,

I've coded sending messege to mail address from website using post in jQuery.

So, I`ve got a form and js like this:

Code:
var fc_name = $('#fc_name').val();
     var fc_company = $('#fc_company').val();
     var fc_phone = $('#fc_phone').val();
     var fc_email = $('#fc_email').val();
     var fc_text = $('#fc_text').val();
     //alert("Zapytanie od: " + fc_name); // for debug
    
     $.post
     (
    
      "<?php echo base_url(); ?>main/send_message",
      
      {
       // post_name:variable_value
      
       fc_name:fc_name,
       fc_text:fc_text
      },
      
      // re show the horizontal menu preview
      function(response){
      
       $('#message_result_box').val("Message has been sended :)");
      
      
      }
    
     )

and the controller method to which I`m sending post from js

Code:
function send_message()
{
  $this->load->library('email');

  $this->email->to('[email protected]');
  $this->email->from('[email protected]');
  $this->email->subject('Here is your info ' . $_POST['fc_name']);
  $this->email->message('This is the text message from website ' . $_POST['fc_text']);
  $this->email->send();
  
}

and in fire bug I`m getting
The URI you submitted has disallowed characters.

I`m using the newest ver of CI

p.s. when I run the controller method from url it sending mail without post vars of course.

#2

[eluser]CroNiX[/eluser]
Is your javascript you listed above in it's own file or is it a part of a php template? If it's a standalone js file, it won't be able to process your php you have in there for the base_url() and sending it as literal text. What URL does firebug say it's being sent to?
#3

[eluser]Krystian[/eluser]
js code is in separate js file

firebug


POST <?php echo base_url(); ?>main/sendmessage
400 Bad Request
943ms
#4

[eluser]CroNiX[/eluser]
Well, as I said, php doesn't get parsed in js files as evidenced by what you just posted (it's not interpreting the php, its posting it literally).

Easiest thing to do is create a js variable in the head of your php template which all of your javascript files can then use.

Code:
var base_url = "<?php echo base_url(); ?>";

Then in your javascript files, just base_url + 'controller/method/etc' to create the urls.
#5

[eluser]Krystian[/eluser]
Thanks Cronix!
or maybe create jQuery function which takes parameter. This parameter would be CI base url.

again thanks






Theme © iAndrew 2016 - Forum software by © MyBB