Home > Web Front-end > JS Tutorial > jquery's $getjson call and get the remote JSON string problem_javascript skills

jquery's $getjson call and get the remote JSON string problem_javascript skills

WBOY
Release: 2016-05-16 17:47:01
Original
1177 people have browsed it

The code is as follows:

Copy code The code is as follows:





Untitled Document





< /body>


where ajax6.asp is
Copy code The code is as follows:

<%
response.Write("{name:'peter',age:18}");
%>

Why can’t I get it? , I want to get the json of asp.
The key problem solved is: key and value require double quotes, as follows:
Copy code The code is as follows:

response.Write("{""name"":""peter"",""age"":""18″"}")

Commonly used in jQuery GetJSON is called to obtain the remote JSON string, convert it into a JSON object, and if successful, execute the callback function. The prototype is as follows:
jQuery.getJSON( url, [data], [callback] ) loads JSON data across domains.
url: the address to send the request
data: (optional) key/value parameters to be sent
callback: (optional) callback function when loading is successful
is mainly used for the client to obtain the server JSON data. Simple example:
Server script, return JSON data:
Copy code The code is as follows:

// $.getJSON.php
$arr=array("name"=>"zhangsan", "age"=>20);
$jarr=json_encode($arr);
echo $jarr;

Note two points: First: before returning to the client, use the PHP function json_encode to encode the returned data. Second: echo is used to return to the client, not return.
The following is the core client code:
Copy code The code is as follows:

< ;script language="javascript" type="text/javascript" src="./js/jquery.js">
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template