Sending multiple variables to PHP

I have the following jQuery-enhanced Javascript within a HTML page: $(document).ready(function() $(“#sb”).click(function(e) e.preventDefault(); getusername = “Yes”; getpassword = “Yes”; getusername = encodeURIComponent(getusername);//url encodes data getpassword = encodeURIComponent(getpassword);//url encodes data $.ajax( type: “POST”, url: “get_login.php”, data: ‘username’: getusername, ‘password’:getpassword, dataType: “json”, success: function(data) $(“#message_ajax”).html(” ” + data.message +” “); …

via PHP Website Development » Search Results » ajax:

Sending multiple variables to PHP

I have the following jQuery-enhanced Javascript within a HTML page:
My php is as follows:
if(isset($_POST[‘username’]) && isset($_POST[‘password’]))
echo json_encode(array(‘message’ => ‘Tester’));
The script isn’t working however. I think it is to do with the way I am posting data from the browser. Perhaps I am incorrectly setting username and password and it is failing upon the isset statement?
Currently, the page does nothing. The button click event handler is triggering…but the message_ajax div in my HTML page isn’t updating with correct response…
…………………………………..

change the line
$(“#message_ajax”).html(“

” + data.message +”

“);to
$(“#message_ajax”).html(“

” + data.message +”

“);and try !!!
…………………………………..

you need to change the mime header… your ajax is expecting json as a respons so you need to set the correct header.
header(‘Content-type: application/json’);http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

For more info: Sending multiple variables to PHP

PHP Website Development » Search Results » ajax

Sending multiple variables to PHP

Share this post:

Related Posts

Leave a Comment