简体   繁体   中英

AJAX only able to connect locally, Not using JSON on server side

The ajax call can is able to do it on locally, but when I change it to let say, my own IP or the server(another machine) IP address then it will is not able to communicate with the server itself?

How can I resolve this? I'm not using JSON on the server so can I still change the dataType to json and use it to connect[tried bu there is error:0 and error:200 for jsonp].

<script>
$(function() {  
  $(".button").on("click",(function() {  
      var cli=$("input#clien").val();
      var use=$("input#username").val();
      var dataString="Clien="+cli+"&UserName="+use;
      $.support.cors = true;
        $.ajax({  
              type: "POST",  
              url: "http://localhost:8080/services/web?wsdl/Authen",  

if I change (to another host PC IP address) it to

url: "http://192.168.1.23:8080/services/web?wsdl/Authen", 

then it will has no response from server.

              data: dataString,
              dataType:'html',

But if i change the dataType to json, the server is able to receive and generate something but no response is able to received on the client side.

              cache: false,
              success: function(data, status, response) {
                alert(response);
            },
              error: function(request,status,response){
                    alert("Error: "+request.status+","+request.statusText);  
              }
            }); 
                return false;   
      }));  
    });  
</script>

Try using relative URI,

for instance change:

url:"http://localhost:8080/services/web?wsdl/Authen"

to

url:"/services/web?wsdl/Authen"

in your ajax request

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