我在我的MooTools脚本中运行一个AJAX调用,这在Firefox中工作正常但在Chrome中我收到Uncaught SyntaxError: Unexpected token :错误,我无法确定原因.注释掉代码来确定坏代码的位置什么都没有产生,我想这可能是返回JSON的问题.检查控制台我看到返回的JSON是这样的:
{"votes":47,"totalvotes":90}
Run Code Online (Sandbox Code Playgroud)
我没有看到任何问题,为什么会出现这种错误?
vote.each(function(e){
e.set('send', {
onRequest : function(){
spinner.show();
},
onComplete : function(){
spinner.hide();
},
onSuccess : function(resp){
var j = JSON.decode(resp);
if (!j) return false;
var restaurant = e.getParent('.restaurant');
restaurant.getElements('.votes')[0].set('html', j.votes + " vote(s)");
$$('#restaurants .restaurant').pop().set('html', "Total Votes: " + j.totalvotes);
buildRestaurantGraphs();
}
});
e.addEvent('submit', function(e){
e.stop();
this.send();
});
});
Run Code Online (Sandbox Code Playgroud) 是否可以将数据发布到JsonP?或者所有数据都必须作为GET请求在查询字符串中传递?
我有很多需要发送到服务的数据,跨域,并且它太大而无法通过查询字符串发送
有什么方法可以解决这个问题?
正在做一些使用jQuery调用我在不同域上的服务.成功调用服务(我的调试点被触发),并返回正确的响应(我嗅探流量).
我的问题主要是成功和失败的回调不会被解雇.我已经在SO上阅读了一些其他帖子,表明在使用JSONP时没有触发错误事件.这是成功事件的情况(也许是因为我假设我提供自己的回调函数),或者有没有办法解雇我的成功回调.提前致谢.
$.ajax({
type: "GET",
url: urlOnDiffDomain,
async: false,
cache: false,
dataType: 'jsonp',
data: {},
success: function(data, textStatus) {
alert('success...');
},
error: function(xhr, ajaxOptions, thrownError) {
alert('failed....');
}
});
Run Code Online (Sandbox Code Playgroud) 我们有一个包含2个项目的简单Visual Studio解决方案:
我们想在调试模式(F5)中简单地启动项目,并让A从B到Ajax消耗数据.我们没有可能在所有开发机器上配置IIS(因为其中一些是在客户端).问题可能是JavaScript需要与其发布的URL位于同一个域中.
有没有什么办法可以使用Visual Studio 2010开发服务器在同一端口上以调试模式同时启动两个应用程序?
如果这是不可能的,那么你可以推荐的下一个最好的东西是什么?
我在这里定义了一个webservice:
/app/AutocompleteManager.asmx
[WebMethod]
public string AutocompleteComposers()
{
return "hey, what's up";
}
Run Code Online (Sandbox Code Playgroud)
我想使用带有额外参数的GET方法来调用它.
如果我去/app/AutocompleteManager.asmx?q=something,它将无法工作,因为我没有指定的操作.
如果我去/app/AutocompleteManager.asmx/AutocompleteComposers?q=something休息.
任何的想法?
我是Web服务的新用户,当我尝试在Chrome控制台中运行我的页面(本地)时出现以下错误
错误
无法加载资源:服务器响应状态为405(方法不允许)
http://localhost:12015/myWebService.asmx?op=GetCategories
这是相关的代码:
jQuery的
$.ajax({
url: "http://localhost:12015/myWebService.asmx?op=GetCategories",
type: "POST",
------------
------------
success: function (data) {
var categories = data.d;
$.each(categories, function (index, category) {
category.CategoryId).text(category.CategoryName);
});
},
error: function (e) { //always executing 'error' only
alert("hello");
}
Run Code Online (Sandbox Code Playgroud)
网络服务网址
http://localhost:12015/myWebService.asmx
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Categories> GetCategories()
{
//code
}
Run Code Online (Sandbox Code Playgroud)
页面URL
http://localhost:11761/Default.aspx
编辑:当我刚刚包括dataType: 'jsonp'但错误消失但现在又出现了另一个错误.
未捕获的SyntaxError:意外的令牌<
:12015/myWebService.asmx?op=GetCategories&callback=jQuery183010907560377381742_1356599550427&{}&_=1356599550438:3
当我点击链接(错误中提到的)时,它正在显示页面.那可能是什么问题?我不知道错误意味着什么(以及代码的哪一部分显示).请帮忙.
有关