0

Ok, I have a controller that returns a response to an ajax call and I'd like to intercept that response in my view. How can I do this?

Alternatively, how could i reference my ajax variable in my view?

View: ContractorList.ascx Controller: HaulerController.cs

2
  • How are you planning to intercept this? The view itself just renders HTML which is sent to the browser. An AJAX call allows the browser to update this rendered HTML on the client itself. Commented Feb 24, 2011 at 15:27
  • Well how can I access an AJAX variable in HTML Commented Feb 24, 2011 at 15:31

1 Answer 1

1

Not sure exactly what you're asking, but I think the answer is something along the lines of this:

$.get("/url/to/action", {/* data you're passing to action */}, function (response) {

    // your result is available here.... 
    // you want to pass it into the callback method as an argument, as above
    // everything your action returns to the page is stored in the response object.

    // can you do something like:
        var idx = response.indexOf('specific string I expect');
        if (idx > -1)
            // the string you expected is there so show popup....

    }, "html");

    return false;
});

If this isn't what you're after, please clarify

Sign up to request clarification or add additional context in comments.

9 Comments

yes I want to access whats in the response object in my view because depending on the value of that response object I want to show a pop up box.
are you returning HTML or JSON to the page?
Sorry I'm a totally newbie perhaps this will clarify your Question.
<!--- HTML VIEW HERE --> I create the objects on my Page etc my dispaly <!-- END HTML VIEW HERE --> <Script type="text/javascript"> $.ajax({ type: "POST", url: "/Hauler/CreateContractor", dataType: "text", data: querystring, success: function(result) { load(); } }); <!----END SCRIPT --> Now i want to check that result variable in my HTML above how can i do that?
then you're probably returning HTML, so you can't inspect the response as an object the way you could if it was JSON. But you do have options. I'll update the answer with a suggestion
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.