我理解JSON,但不了解JSONP.维基百科关于JSON的文档是JSONP的最佳搜索结果.它说:
JSONP或"带填充的JSON"是JSON扩展,其中前缀被指定为调用本身的输入参数.
咦?什么电话?这对我没有任何意义.JSON是一种数据格式.没有电话.
JSONP是脚本标记注入,将响应从服务器传递到用户指定的函数.
我可以理解这一点,但它仍然没有任何意义.
那么什么是JSONP?它为什么被创建(它解决了什么问题)?为什么我会用它?
附录:我刚刚在维基百科上为JSONP创建了一个新页面 ; 根据jvenema的回答,它现在对JSONP进行了清晰而全面的描述.
我正在使用JQuery ajax jsonp.我有以下JQuery代码:
$.ajax({
type:"GET",
url: "Login.aspx", // Send the login info to this page
data: str,
dataType: "jsonp",
timeout: 200000,
jsonp:"skywardDetails",
success: function(result)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
}
});
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,我只想将请求发送为"POST"而不是"GET",请建议我如何实现这一点.
谢谢
我想用jquery ajax用以下代码解析JSON数组数据:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample</title>
<script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var result;
function jsonparser1() {
$.ajax({
type: "GET",
url: "http://10.211.2.219:8080/SampleWebService/sample.do",
dataType: "jsonp",
success: function (xml) {
alert(xml.data[0].city);
result = xml.code;
document.myform.result1.value = result;
},
});
}
</script>
</head>
<body>
<p id="details"></p>
<form name="myform">
<input type="button" name="clickme" value="Click here to show the first name" onclick=jsonparser1() />
<input type="text" name="result1" readonly="true"/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的JSON数据是:
{"Data": [{"Address":"chetpet","FirstName":"arulmani","Id":1,"LastName":"sathish","City":"chennai"},{"Address":"ramapuram","FirstName":"raj","Id":2,"LastName":"nagu","City":"chennai"},{"Address":"ramapuram","FirstName":"raj","Id":2,"LastName":"nagu","City":"chennai"},{"Address":"ramapuram","FirstName":"ramaraj","Id":3,"LastName":"rajesh","City":"chennai"},{"Address":"ramapuram","FirstName":"yendran","Id":3,"LastName":"sathi","City":"chennai"}],"Code":true}
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何输出......任何人请帮助...
我需要检查,如果Youtubeurl不存在我应该抛出错误,我按照这个答案并创建了jsfiddle来检查它.
它适用于有效网址但不适用于无效网址.我只看到404错误network console

有没有办法检查客户端是否存在url使用JavaScript和jQuery.
这是我的代码:
var videoID = 'kn8yzJITdvI';//not working
//var videoID = 'p4kIwWHP8Vc';//working
$.ajax({
url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json",
dataType: "jsonp",
success: function(data) {
console.log(data)
$("#result").text(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
// Handle errors here
alert('ERRORS: ' + textStatus);
}
});
Run Code Online (Sandbox Code Playgroud)
javascript ×3
jquery ×3
ajax ×2
json ×2
jsonp ×2
http-post ×1
terminology ×1
youtube ×1
youtube-api ×1