1

I have this part of ajax code on my windows8

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "></script>
<script>
$(document).ready(function(){
    $('#next_Button').click(function(){

        var text = document.getElementById("textbox");
        var query = text.value;
        $('#response').html("<b>Loading response...</b>");

        $.ajax({
            type: 'POST',
            url: 'http://192.168.92.131/search2/info.php', 
            data: { query : query }
        })
        .done(function(data){
            $('#response').html(data);
            alert("sent query");             
        })
        .fail(function() {         
           alert( "Posting failed." );
        });

        return false;

    });
});
</script>

and php code on my virtual Ubuntu machine

echo $_POST['query'];

IP address is correct and it's always fixed. But ajax always says 'posting failed'. when I put html code on server and just set url :'search2/info.php' it works. but when it's remote server with http:// ipaddress / search2 / phpname it doesn't work. By the way my php code is in var/www/html/search2 hosted on apache. Is this problem from ajax ? even when I click on this complete url it shows server page! but ajax can't use this direct url to .php !

xkickflip
  • 768
  • 6
  • 17
patric
  • 17
  • 10

2 Answers2

2

Ajax has a cross domain protection, to prevent loading from domain others than then one you browse to.

This is a security feature. I suggest you read about it a bit here: jQuery AJAX cross domain

And there are many other questions on the subject.

Igal S.
  • 9,704
  • 4
  • 28
  • 43
0

I 'm really glad to find it myself !! I 'v open .html by double click (it was really wrong and I never noticed) and now I understand open it on localhost or 127.0.0.1 !it works properly . before , alert shows it works but there were no answer from server ... And also it printed whole page!! see , I had lots of comments after the tag so it echo all of comments :)

patric
  • 17
  • 10