我正在尝试一个简单的ajax
post
请求。它在localhost中运行良好。但是一旦我上传到服务器,我就会收到405 Method Not Allowed
错误。我搜索了很多解决方案,找不到任何有用的东西。
这是我的Ajax
:
$("#fav").click(function(){
$.post('/myFav/', { entry_id:$("#entryId").val() }, function (data) {
$("#favCount").empty().append(data.count);
alert(data.msg);
});
});
我的路线定义是:
Route::post('/myFav', 'EntryController@favorite' );
在localhost但服务器上一切正常。 需要帮助请叫我。
响应标题
Response request
Allow:POST
Cache-Control:no-cache
Connection:close
Content-Length:218
Content-Type:application/json
Date:Fri, 15 May 2015 17:42:07 GMT
Server:Apache/2.4.7 (Ubuntu)
Set-Cookie:laravel_session=eyJpdiI6IlhtbVMyREJMY3RGU2pnU2VQNmlma0E9PSIsInZhbHVlIjoiTjd3dXBaU0lBa2hGVHp5WnlGaHduRmIrcVArUnJSbndKY2ZiczR2QlBsdEpkekRjM1oyT1FUZVNEVkhKbDZcL0ZJM1lIdmdiQUhHdlU5YVpnM2g0U3hnPT0iLCJtYWMiOiJkMmE3ZDc5N2QyMTBjMzk5Mjk3YmIxZjEyZmNkYTYwYmVjZTczMzc5NDYyMjBmZGExMWI2YWFmNTNjZTEwY2IxIn0%3D; expires=Fri, 15-May-2015 19:42:07 GMT; Max-Age=7200; path=/; httponly
X-Powered-By:PHP/5.5.9-1ubuntu4.7
和请求标题
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
AlexaToolbar-ALX_NS_PH:AlexaToolbar/alxg-3.3
Connection:keep-alive
Cookie:laravel_session=eyJpdiI6Ikxhak9KbVRMZ2ZpS0kzYzl2dXM3XC9BPT0iLCJ2YWx1ZSI6ImxCMGs2NzU0SjFKTVR4QTJlc3NzbnZ3ZGl3RFU0bk5LRDI2V2MzbXVZdFlaM2p2cmx2bW81NDVrU2ROeVZQZThnQk8xK3hUeG9VQVlRNnoxS0x1UWhRPT0iLCJtYWMiOiJjMjBjMDNmMTc0YjEwNGQ5MzgzYjM3ZmEyYzQ5Y2NkNGY3MzFmZDU1MDEwN2FjNWIxZDNiNGU0NWNmMjNhZDU2In0%3D
Host:ambrella.co
Referer:http://xxxxxx.co/26/cos
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
X-Requested-With:XMLHttpRequest
答案 0 :(得分:0)
我不确定,问题是什么,但是当我改变
时 post
url
至\entries\myFav
它奏效了。可能是字符长度有些问题!不过不确定。
所以最终的代码变成了:
$("#fav").click(function(){
$.post('/entries/myFav/', { entry_id:$("#entryId").val() }, function (data) {
$("#favCount").empty().append(data.count);
alert(data.msg);
});
});