Search code examples
javascriptphpajaxspecial-characterssend

Retrieve special character in php send via ajax


I am using ajax jquery to send data to php, as data I am sending one url as string from ajax that contains special character i.e "&" So I'm not getting full url i.e. my data it retrieved until '&' only rest id ignored and not displayed.

Below is my code for ajax and php:

dummytest.php

$temp=$_POST['address'];
echo $temp;

test.html (ajax to send data )

    var send="http//192..../oracle/master.php?result=2&table=1"
    $.ajax({
        type: "POST",
        url: "dummytest.php",
        dataType: "text",
        data: send,
        success: onSuccess,
        error: onError
         }); 

I'm sending data "send" i.e one url as string data but I'm receiving it until "&" only in my php i.e.

http//192..../oracle/master.php?result=2

Can any one tell me how can I get my full data/url ?


Solution

  • You are sending the URL as the whole body of the POST request, while on the PHP side you are expecting to find it in the address parameter. You should change send on the Javascript side to

    var send = { address: 'http://...' }
    

    and jQuery will take care of encoding it in the body of the request.