java - JQuery, ajax, port number -


how json server http://localhost:2323 if $.ajax in jquery doesn't work. json generated width java class:

public class main {     public static void main(string[] arr) {         new main().start();     }     protected void start() {         (;;) {             try {                 socket remote = new serversocket(2323).accept();//port number                 bufferedreader in = new bufferedreader(new inputstreamreader(                         remote.getinputstream()));                 printwriter out = new printwriter(remote.getoutputstream());                 string str = ".";                 while (!str.equals(""))                     str = in.readline();                 out.println("http/1.0 200 ok");                 out.println("content-type: text/html");                 out.println("server: bot");                 out.println("");                 out.print("{\"a\":\"a\",\"b\":\"asdf\",\"c\":\"j\"}");                 out.flush();                 remote.close();             } catch (exception e) {                 system.out.println("error: " + e);             }         }     } } 

that outputs {"a":"a","b":"asdf","c":"j"}. , jquery script is

$(document).ready(function() {     $.ajax({         type: 'post',         datatype: 'json',         url: 'http://localhost:2323',//the problem here         async: false,         data: {},         success: function(data) {             alert(data.a+' '+data.b+' '+data.c);         }     }); }); 

if url http://localhost, works, if append :portnumber, doesn't work. how read url:portnumber?

thanks

specifying port in ajax calls won't work due same origin policy (http://en.wikipedia.org/wiki/same_origin_policy). means url must have same domain , port server, script's hosted.

also, please note question asked, , 1 of first results when searching in google - is possible specify port in ajax call


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -