2014年1月3日 星期五

jquery=getjson



http://stackoverflow.com/questions/6643838/jquery-ajax-parsererror


it's because you're telling jQuery that you're expecting JSON-P, not JSON, back. But the return is JSON. JSON-P is horribly mis-named, named in a way that causes no end of confusion. It's a convention for conveying data to a function via a script tag. In contrast, JSON is a data format.
Example of JSON:
{"foo": "bar"}
Example of JSON-P:
yourCallback({"foo": "bar"});

server side

String callback = request.getParameter("callback");
String _r = callback ;
out.print(_r);
out.print("({\"foo\": \"bar\"});");



Client Side 


s4=_lookup("lingual");
s3=<%=bean.getRecordid().trim()%>;
s= "tableWrite?"+
"db=erp&"+
"table=USER&"+
"fields=lingual&"+
"values='"+s4+"'"+
"&key=recordID&value="+s3+
"&callback=?";
url=s;


$.ajax({
 url: url,
 async:false,
 dataType: 'json',
// jsonpCallback: 'alert("fnsuccesscallback");',
 success: function(result){
alert(1);
alert("token recieved: " + result.token);
 },
 error: function(request, textStatus, errorThrown) {
alert(2);
alert(textStatus);
 },
 complete: function(request, textStatus) { //for additional info
alert(3);
alert(request.responseText);
alert(textStatus);
//window.open("http://www.google.com.hk","_blank")
//window.open("index.jsp","_blank")
//location.reload();
//window.open("index.jsp","_self")
//window.location.replace("http://stackoverflow.com");
 }
});



//document.write(s);


$.getJSON(s,
function(data) {
if (data[0]){
alert(11);

}  else {
alert(22);
$.getJSON(s,
function(data) {
if (data[0]){
alert(11);

}  else {
alert(23);
}
}
); //endofgetJson
}
}
); //endofgetJson

沒有留言:

張貼留言