#1
  1. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,150
    Rep Power
    144

    JQuery $.post with MVC framework


    Hi--

    I've inherited a very poorly built website that uses an MVC framework and need to build a page that would really benefit from JQuery's $.POST functions so I don't need to reload the page so often.

    Trouble is, my return values are the source code of the page I'm sending from and the data I need.

    Apart from building the form submit code into the controller and model, is there a way to achieve this? It would be a huge time saver if I can.

    Thanks!
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,230
    Rep Power
    4149
    When you get your HTML response, use jQuery.parseHTML to convert it to a DOM structure then you can use standard DOM methods to grab the data you need and import it into the current document.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,150
    Rep Power
    144
    Thanks @kicken. I've tried that, but only get the HTML back, not the data I need.

    As a quick way to test, I'm POSTing to a script called get.php. That page only echoes the word "hey", but all I see in the callback function is the HTML. Here is my Javascript:

    Code:
    $("#update").click(function() {
    		$.post("get.php",function(data) {
    			alert(data);
    		});
    	});
    As I said, I'm only looking for "hey", but I get all the HTML code from the page sending this request. "hey" is not returned anywhere.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  6. #4
  7. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,230
    Rep Power
    4149
    If you're not getting the data you expect back then you're not making the correct request. You need to figure out what the correct request is to get that data first.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  8. #5
  9. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,150
    Rep Power
    144
    Originally Posted by kicken
    If you're not getting the data you expect back then you're not making the correct request. You need to figure out what the correct request is to get that data first.
    And that circles me back to this being a poorly developed site. I've tried a few different methods and all have failed. Looks like I'm boned and will just have to reload the page after each request.

    Thank you, though, for your help. Anyone can learn a language, not everyone can learn to code properly.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  10. #6
  11. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,230
    Rep Power
    4149
    You can probably figure out what you're missing by just using the browser's network inspection tools (or a proxy like fiddler). It's probably something simple like needing a certain parameter or maybe you need to use GET rather than POST.

    Just load up the page then check the tool to see what was submitted to the server and simulate that in your ajax request.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  12. #7
  13. Plays with fire
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    1,150
    Rep Power
    144
    Originally Posted by kicken
    You can probably figure out what you're missing by just using the browser's network inspection tools (or a proxy like fiddler). It's probably something simple like needing a certain parameter or maybe you need to use GET rather than POST.

    Just load up the page then check the tool to see what was submitted to the server and simulate that in your ajax request.
    I've tried using GET and no luck there. Good idea about the tools. I hadn't thought of that. Still, I suspect I'm just going to have to submit the form.

    This whole site is due for an overhaul anyway, it's just finding the time and hopefully minimizing these new requests until I'm done.

    Thank you again!
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence

IMN logo majestic logo threadwatch logo seochat tools logo