SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Data strings sent thru AJAX techniques and how PHP interprets them

    I created an HTML table list that uses jQuery sortable and droppable features. When I reorder the list by dragging a row to another location in the list, all works perfectly well. The PHP code called on by the jQuery ajax technique ".load()" works correctly too, and the server side table column gets updated with new "position" values, just like I want.

    When I drag a row to the little trash bin div I created, the browser side responds correctly but the server side does not. I'm having trouble passing the correct values to the PHP code to trigger the isset($_POST['row']) condition. I've tried with both .load() and .ajax() so far. I'm attempting the long form XMLHttpRequest code now.

    I've given all the HTML table rows, and therefore the draggable row, an 'id' that makes sense according to a lot of the literature and forums I've read, for example: <tr id="row_16">. I've seen that the 'name' should be setup when constructing the params string to be sent as the data for the POST type request too: <tr name="row_16">.

    What I'm trying to accomplish, and where my knowledge is lacking, is in getting this 'id' or 'name' related value of 16 to feed to the PHP code in order to create the SQL command that will delete the row in the database table of the server that corresponds with database table's column id value of 16.

    If I can fully understand what goes into creating the format for the data sent thru the XMLHttpRequest such as "data:...", params or a serialized string and how PHP interprets them, I should be able to implement POSTs with any of the ajax techniques I've been exposed to so far.

    Any insight on how these strings are created and packaged for PHP to be able to parse would be appreciated. Or if someone could point me to literature that does a good job of explaining this, I'd be grateful.

    Sorry for the long winded question. I hope it's clear though.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    THe jQuery ajax page says that if the data is not already a string, that it is serialized to one, which is also called stringify.

    The json.org web site provides resources for a vast number of languages, including javascript. The json2.js script from douglas crockford's json-js is the preferred library to use for JSON techniques.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paul...I read through the links and will look for opportunities to begin using the JSON format. Thanks.

    Using JavaScript, I was able to '.split()' the value (16) off of the id value (row_16) and feed it to the PHP file thru the XMLHttpRequest and then supply that value to my SQL command for deleting the associated row from the database table. Now the droppable feature works the way I want.

    How would you have applied the JSON format to such an issue, and why would it be a preferred method in the context of Javascript to AJAX to PHP? Just curious. If JSON formatting could be applied in this context, it would clear up those questions for me.

    Thanks again.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by ryan77 View Post
    How would you have applied the JSON format to such an issue, and why would it be a preferred method in the context of Javascript to AJAX to PHP? Just curious.
    Thanks to your second reply, it's become clear that your problem was not related to the format of the data, or serializing the data for transfer, as was initially stated, so your initial line of reasoning would not have helped to resolve your predicament.

    Well done on getting it resolved.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

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
  •