nhayder
2 weeks ago

Axios ajax call not working on shared hosting but works on localhost

Posted 2 weeks ago by nhayder

hi, i have an issue with ajax call after i deployed my app on share hosting, This function is working on local host and it giving this error on shared hosting.

"message": "The GET method is not supported for this route. Supported methods: POST.",

this is the error as i see on safari devTools

Summary
URL: http://myapp/api/widget/pullwbtnleft/
URL: http://myapp/api/widget/pullwbtnleft
Status: 405 Method Not Allowed
Source: Network
Address: 127.0.0.1:12080
Initiator: 
designer.js:256


Request
GET /api/widget/pullwbtnleft/
Accept: application/json, text/plain, */*
Content-Type: application/json;charset=utf-8
Referer: http://myapp/en/admin/designer/1
Origin: http://myapp
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15
X-Requested-With: XMLHttpRequest
X-CSRF-TOKEN: MIQlRhUWynkc4GElMfPJWdbkckHd7tKNzM4ktUnF
X-XSRF-TOKEN: eyJpdiI6Imh2WWgzRlhPcmc2VDFFMVdsZ1NzRlE9PSIsInZhbHVlIjoiTmdQWTZZcGtiT0VKRndQMG9Wa2pPMm9aS2NkYzZUUnhOVEpld1M2XC9yWWFPNG5UV0txRStFQWo0ZEZZS0FxcHciLCJtYWMiOiI0OTJiOWMzZGQwMGEyMGY0NjQ5MDU5Mjg5NTllMmVhMWQ1ZjhhOTMxNTNjOGY1NjEwMGY0OTAzOTY2ZjkyNTk3In0=

Redirect Response
301 Moved Permanently
Location: http://MyApp.com/api/widget/pullwbtnleft
Date: Fri, 20 Mar 2020 08:49:47 GMT

Request
POST /api/widget/pullwbtnleft HTTP/1.1
Accept: application/json, text/plain, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Host: MyApp.com
Origin: http://MyApp.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15
Connection: keep-alive
Referer: http://MyApp.com/en/admin/designer/1
Cookie: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cmc2VDFFMVdsZ1NzRlE9PSIsInZhbHVlIjoiTmdQWTZZcGtiT0VKRndQMG9Wa2pPMm9aS2NkYzZUUnhOVEpld1M2XC9yWWFPNG5UV0txRStFQWo0ZEZZS0FxcHciLCJtYWMiOiI0OTJiOWMzZGQwMGEyMGY0NjQ5MDU5Mjg5NTllMmVhMWQ1ZjhhOTMxNTNjOGY1NjEwMGY0OTAzOTY2ZjkyNTk3In0=
X-CSRF-TOKEN: MIQlRhUWynkc4GElMfPJWdbkckHd7tKNzM4ktUnF

Response
HTTP/1.1 405 Method Not Allowed
Content-Type: application/json
Cache-Control: no-cache, private
Vary: Accept-Encoding,User-Agent
Date: Fri, 20 Mar 2020 08:49:48 GMT
Content-Encoding: gzip
Keep-Alive: timeout=5, max=99
Content-Length: 718
Connection: Keep-Alive
Server: Apache
Allow: POST

Request Data
MIME Type
Request Data: 

this is the function on vuex

        async pullWbTNleft({commit}, [id, sort, wID, wIndex]){
            
            commit('WORK_ON');

            await axios.post('/api/widget/pullwbtnleft/', {

                id: id,

                sort : sort,

                wID : wID,

            })

            .then(function (response) {

                commit('PULL_W_BTN_LEFT', [wIndex, response.data])

            })

            .catch(function (error) {

                Event.$emit('requestAlertDanger'); 

            });

        },

this is the route

	Route::post('/widget/pullwbtnleft', '[email protected]');

this is the pullWidgetBtnLeft function

    public function pullWidgetBtnLeft(Request $request)
    {
    
        $request->validate([

            'id' => 'required|integer',

            'sort' => 'required|integer',

            'wID' => 'required|integer',

        ]);

        
        // code logic goes here

    }

can anyone see what the problem is ????

and how to fix this issue ???

Please sign in or create an account to participate in this conversation.