www.webdeveloper.com
Results 1 to 2 of 2

Thread: Parse Results for an ID

  1. #1
    Join Date
    Sep 2009
    Posts
    172

    Parse Results for an ID

    All,
    If I have the following code:
    Code:
    Code:
    var http_request = false;
       function makePOSTRequest(url, parameters, str) {
          http_request = false;
          if (window.XMLHttpRequest) { // Mozilla, Safari,...
             http_request = new XMLHttpRequest();
             if (http_request.overrideMimeType) {
             	// set type accordingly to anticipated content type
                //http_request.overrideMimeType('text/xml');
                http_request.overrideMimeType('text/html');
             }
          } else if (window.ActiveXObject) { // IE
             try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
             } catch (e) {
                try {
                   http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
             }
          }
          if (!http_request) {
             alert('Cannot create XMLHTTP instance');
             return false;
          }
    
          http_request.onreadystatechange = alertContents;
          http_request.open('POST', url, true);
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          http_request.setRequestHeader("Content-length", parameters.length);
          http_request.setRequestHeader("Connection", "close");
          http_request.send(parameters);
       }
    
       function alertContents() {
          if (http_request.readyState == 4) {
             if (http_request.status == 200) {
                //alert(http_request.responseText);
                result = http_request.responseText;
                document.getElementById('myspan').innerHTML = result;
    			window.location.hash = "#picture_id";
      			resizeAll();
             } else {
                alert('There was a problem with the request.');
             }
          }
       }
       
       function getpic(obj) {
    	  var poststr = "picture=" + encodeURI( document.getElementById("picture").value );
          makePOSTRequest('getnextpic.php', poststr);
       }
    How can I parse:
    Code:
    result = http_request.responseText;
    So I can get a picture_id so I can update my hash on this line?
    Code:
    window.location.hash = "#picture_id";
    I tried this:
    Code:
    var imgs = document.getElementsByTagName("img");
    for ( var d = 0; d < imgs.length; ++d )
        {				
         var img = imgs[d];
         if ( img.className == "showpictureid" )
            {
    	      imgid = imgs[d].getAttribute("id");
    	      //alert("The image id is" + imgid);
    	}
    }
    But it doesn't work. The PHP code is:
    PHP Code:
    echo "<div style=\"position:relative;\"><img src=\"uploaded_files/$resultsetstory[image_id]\" class=\"showpictureid\" id=\"$resultsetstory[image_id]\" onclick=\"javascript:getpic(this.myform2);\"></div>"
    Last edited by Kor; 11-06-2009 at 08:27 AM. Reason: Wrap the code [code][/code]

  2. #2
    Join Date
    Nov 2009
    Posts
    36
    Your javascript pieces are fine, and the code should return the ids. Are you sure about your php script being executed and the results received by the browser?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles