ryandawkins
ryandawkins

Reputation: 1545

Bad Request Error when making AJAX request using JQuery-2.0.3

I'm not sure what is wrong with this request, but here is what is happening..

It appears the browser thinks I am making a cross-domain request, however I am making a request to the same page that the request comes from.

I call a function called search, and I am returned this in my google chrome dev console

EDIT:

The same thing happens when I load jquery-1.0.2.min.js
The server returns this: {"readyState":4,"status":404,"statusText":"error"}

Bad request                                               search.js?1383509337:48
POST http://example.com/transaction/search   jquery-2.0.3.js:7845
x.support.cors.e.crossDomain.send                         jquery-2.0.3.js:7845
x.extend.ajax                                             jquery-2.0.3.js:7301
search                                                    search.js?1383509337:22
(anonymous function)                                      search.js?1383422028:17
x.event.dispatch                                          jquery-2.0.3.js:4676
y.handle                                                  jquery-2.0.3.js:4360

Function search()

function search(user, transactionDate, vendorField, amountField, accountField, departmentField, subDepartmentField, statusField, projectidField){

    var url = "/transaction/search";
    var ajax = jQuery.ajax({
        type: 'POST',
        dataType: 'json',
        url: url,
        data: {
            user: user,
            transactionDate: transactionDate,
            vendorField: vendorField,
            amountField: amountField,
            accountField: accountField,
            departmentField: departmentField,
            subDepartmentField: subDepartmentField,
            statusField: statusField,
            projectidField: projectidField
        },
        beforeSend: function(data){
            $('#searchSpinner').show();
            console.log("Sending request");
        },
        success: function(data){
            console.log("Successful request");
            data = JSON.parse(data, true);
            loadTransactions(data['response']['transactions']);
            $('#searchSpinner').hide();
        },
        error: function(data){
            console.log("Bad request");
            $('body').html(JSON.stringify(data));
            $('#searchSpinner').hide();
        }
    }).done(function(data){
        console.log("finished");
        $('#searchSpinner').hide();
    });

}

Upvotes: 1

Views: 2831

Answers (1)

ryandawkins
ryandawkins

Reputation: 1545

Turns out the problem wasn't with the AJAX request, but a bad formed MySQL query was taking up too much resource time and the page time'd out.

Upvotes: 1

Related Questions