function submitData()
{
var id = jQuery("input[name=Id]").val();
var review = jQuery("input[name=review]").val();
var dataString = 'id='+ id
+'&review ='+ review;
alert(dataString);
jQuery.ajax({
type: "POST",
url: "<?php echo base_url();?>mycontroller/myfunction",
dataType: "json",
data : dataString,
success: function(e) {
alert(e);
}
});
};
IN Controller-
funciton myfunction()
{
$data = array("id" => $this->input->post('id'),
"review" => $this->input->post('review')
);
var_dump($data);
}
In console i am getting wrong response, it's redirecting to other page. and i am getting response from these page, i checked these controller name and method name.
you have syntax error in your function
function myfunction()
{
$data = array("id" => $this->input->post('id'),
"review" => $this->input->post('review')
);
var_dump($data);
}
Just a shot in the dark.
var dataString = 'id ='+ id +'&review ='+ review;
There is an extra space just before the "=" sign.
Can you try removing that, like so?
var dataString = 'id='+ id +'&review='+ review;
Example check
without space in parameter - Works
http://api.duckduckgo.com/?q=something&format=json&pretty=1
with space in parameter - Doesn't work
http://api.duckduckgo.com/?q%20=something&format=json&pretty=1
try this
var id = 1;
var review = 'test';
//var dataString = 'id='+ id
//+'&review ='+ review;
// alert(dataString);
jQuery.ajax({
type: "POST",
url: "<?php echo base_url();?>index.php/admin/admin/myfunction",
dataType: "json",
data :{id:id,review:review},
success: function(e) {
alert(e);
}
});