jquery - Best way to send parameters to php controller with AJAX -
i want sent 2 parameters client ( jquery ) side server side ( php-codeigniter ). parameters id ( integer ) , text ( string ). tried:
window.location.href="ajaxupdate/sendmessage/"+id+"/"+text;
which has worked me in past using id, because text string can have spaces can get:
http://localhost/b1/mycontroller/myfunction/3/gdfgdgd%20 %20 gd
which gives:
an error encountered uri submitted has disallowed characters.
what best way prepare , transmit string server side using jquery? assume ajax used in way
you can use jquery .ajax()
function post data (json
) php script, this:
var postdata = { "param1" : some_value1, "param2" : some_value2 }; console.log(postdata); $.ajax({ type: "post", url: "test.php", data: postdata, success: function(){ alert(param1 + ' ' + param2); window.open("test.php"); } });
update:
php sample googled , found; doesn't seem much, unfortunately not versed in php @ all:
//request parameters $param_1 = $_post['param1']; $param_2 = $_post['param2']; echo 'postdata: ' . var_dump($_post); if ($_post)){ echo $param_1; echo $param_2; } else { echo 'problem'; }
Comments
Post a Comment