简体   繁体   中英

Cross Domain URL in jQuery

I have made a very simple index.php code as following

<!DOCTYPE html> 
<head> 
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/httpGet.js"></script>
<script type="text/javascript" src="js/jquery.mobile.js"></script>   

</head> 

<body>
 <input id="string" type="text"/>
 <input id="button" type= "button" value="Check" />

</body>
</html>

In this HTML code we get a number fro user and call httpgGet.js file. And the httpGet.js is :

$('#button').click(function() {
        var string = $('#string').val();
    $.post('http://...../isprime.php',{number: string},function(data){
      alert(data);
            } 
     }

we send the user number to a isprime.php file where it checks if a user number is a prime number or not. When I say $.post('php/isprime.php',.....) it works very well, but when I want to call the isprime.php from another computer, it does not work.

I mean $.post('192.168.1.1/test/isprime.php'....) gives me a not found error.

The file exists and I am able to run the code using direct call from browser. When I type in browser 192.168.1.1/test/isprime.php the file is reachable, but from the js file, it fails. Obviously, I can ping 192.168.1.1 too. I checked the code even with FireBug and no way thorough.

I searched a lot and came a cross that Browsers do not allow cross domain call (for security purpose, I guess), but I cannot find a solution to get rid of this problem. There are something about YQL (which is a query language and I don't know if I can use it or not). Also I saw something about cULR but I am not sure if that works too.

Kindly help. I really need it. thank u very much.

The most obvious solution, in my opinion, would be to make the request on the server side where you do not have the cross-domain request restrictions using the cURL library (as you mentioned, yes it would work). Of course, you would need to have the cURL library installed on your server. The PHP cURL manual should have enough information to get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM