AlexGH AlexGH - 2 months ago 30
Ajax Question

Ajax not recognized in JQuery file

I uploaded to GitHub days ago an MVC project, I've downloaded it again, and want to set some new functions using JQuery Ajax, but now when I'm trying to do something like this:

$("#btnTrigger").click(function () {
$.ajax({
type: "get",
url: "/Orders/MyJson/"
}).success(function (result) {
alert(result.testing)
})
});


An exception is thrown:
Object doesn't support property or method 'success'
.
I think that something is wrong with JQuery, when I'm going to write
$.ajax
inside a function the keyword
ajax
is not displayed, instead Intellisense shows other keywords like
attr
etc. Normally the keyword
ajax
is displayed from Intellisense.
I've been trying uninstaling and installing JQuery again and nothing happened, I've check the BundleConfig class to check if the JQuery files are added and they are there, I've installed unobtrusive ajax and have added it to BundleConfig class too and still the problem continues... What it could be??

Answer

Try it like this, putting the success inside ajax definition

$("#btnTrigger").click(function () {
        $.ajax({
            type: "get",
            url: "/Orders/MyJson/",
            success: {
                function (result) {
                alert(result.testing);
            }
        }})})