SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: AJAX segments?

  1. #1
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,734
    Mentioned
    31 Post(s)
    Tagged
    1 Thread(s)

    AJAX segments?

    Since the data am transmitting is exactly the same I am trying to 'piggyback' an AJAX request so that the resulting text can be split between two separate elements. I have done this before but it's been a stressful week and am drawing a blank.


    Essentially the processing document returns this text:

    "<DIV id='area1'> ... HTML for area 1 </DIV>
    <DIV id='area2'> ... HTML for area 2 </DIV>"

    I thought there was a way got get the AJAX call to return each ID'ed element as a SEPARATE ELEMENT but IN THE SAME CALL, if that makes sense

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Try get the returned value with the two segments in JSON format:
    Code:
    {"area1": "HTML for area 1",
    "area2": "HTML for area 2"}
    Transform the JSON string in object, for example with:
    Code:
    var myObject = JSON.parse(JSONstring);
    Then, get each element and add it into <div> .
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,734
    Mentioned
    31 Post(s)
    Tagged
    1 Thread(s)
    ah makes sense!, thanks MarPlo!

    I think what I was remembering involved jQuery, which I guess parses the HTML response.. but as I normally try to avoid libraries when I can, this would be a great way of doing the same.

    I was also going to try a text split. The problem , of course would have been that I would have to make a ridiculously unusual delimiter , as I am dealing with nested code.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •