Just to record the next three kinds of jsonp ways, $.get (URL, callback) way, error--must indicate the return type is "JSON" line.
You must use $.getjson () or $.ajax ({}).
<!DOCTYPE HTML><HTMLLang= "en"> <Head> <MetaCharSet= "Utf-8"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"> <Metaname= "Viewport"content= "Width=device-width, initial-scale=1"> <Metaname= "description"content=""> <Metaname= "Author"content=""> <!--<link rel= "icon" href= ". /.. /favicon.ico "> - <title>Query by latitude coordinate</title> <!--Bootstrap Core CSS - <Linkrel= "stylesheet"href= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"> <!--Custom Styles for this template - <Linkhref= "Signin.css"rel= "stylesheet"> <!--Just for debugging purposes. Don ' t actually copy these 2 lines! - <!--[If Lt IE 9]><script src=]. /.. /assets/js/ie8-responsive-file-warning.js "></script><! [EndIf] - <!--<script src= ". /.. /assets/js/ie-emulation-modes-warning.js "></script> - <Scriptsrc= "Http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></Script> </Head> <Body> <Divclass= "Container"> <formclass= "Form-signin"role= "form"> <H2class= "Form-signin-heading">Query by latitude coordinate</H2> <inputtype= "text"class= "Form-control"ID= "Address"placeholder= "Address"Required Autofocus> <inputtype= "text"class= "Form-control"ID= "Location"placeholder= "Location"ReadOnly> <Buttonclass= "btn btn-lg btn-primary btn-block"type= "button">Inquire</Button> </form> </Div> <!--/container - <!--IE10 viewport hack for surface/desktop Windows 8 bug - <Scriptsrc=".. /.. /assets/js/ie10-viewport-bug-workaround.js "></Script> <Script> $(function(){ $(". BTN"). On ('Click',function(){ varAK="your secret key."; varURL= "http://api.map.baidu.com/geocoder/v2/?address="+$("#address"). Val ()+"&output=json&ak="+AK+"&callback=?"; //$.getjson (URL, function (data) {///using $.get () will error, get does not support JSONP? is not unsupported, but default non-JSON format it$.get (URL,function(data) {//using $.get () will give an error and you must specify the return type as JSON! //Alert (json.stringify (data)) $("#location"). Val (Data.result.location.lat+ ', '+data.result.location.lng); }, "JSON"); //The return type must be specified as JSON-side! /*$.ajax ({//This can be URL: "http://api.map.baidu.com/geocoder/v2/", Jsonp: "Callback" , DataType: "Jsonp", data: {address: $ ("#address"). Val (), Output: "JSON", Ak:ak}, Work with the response Success:function (response) {Console.log (response . result.location); Server Response $ ("#location"). Val (Response.result.location.lat + ', ' +response.result.location.ln g); } });*/ }); }); </Script> </Body></HTML>
Use Baidu Map API to query latitude and longitude according to address