...

View Full Version : AJAX: JS callback via PHP: what can I do with an [object NodeList]?



syntax_error
03-31-2010, 11:37 AM
Greetings,

just dropped by here, looks quite nice with you guys here...

Well.
I wanted to send a form content to a jsPrep() ( = prepare) function in JS, then (silently) pass this to PHP.
The tricky thing is that this here is an ARRAY and can be implode()'d easily if and only if the PHP script is specified in the action=... attribute.

However, if I prepare some stuff in my JS caller script, and pass it to PHP as a second step, I get a [object NodeList] inside PHP which I do not know what to do with...

Looks like this:

[html]


<form name="suchform2" action="" onSubmit="jsPrepPhp('thephp',this.form['rsel[]']);return false;">

<input type="checkbox" name="rsel[]" value="101">
<input type="checkbox" name="rsel[]" value="102">
<input type="checkbox" name="rsel[]" value="103">
<input type="checkbox" name="rsel[]" value="104">

<input type="button"
value="send" onClick="jsPrepPhp('thephp',this.form['rsel[]']);return false;">
</form>


[js]


jsPrepPhp = function (ajaxPHP, prm1)
{
var phpfile = ajaxPHP + ".php";
var enc=window.encodeURIComponent||window.escape;
var paramStr = 'p1[]=' + enc(prm1);
send2PHP(phpfile,paramStr);

// NOTE: send2PHP() is the common XMLHttpRequest stuff
}


{php} (via ajax)


$prm_array1=$_POST['p1'];
$prm_array_text = implode(', ',$prm_array1);


This does not really work because as p1 I get a object NodeList from my JS caller script and I dunno why I get this nor can I do anything with it in my case.
Is there any way to rewrite it so that the implode() works as if I had directly specified the PHP in the action attribute in the <form>?
(Which does not work in my case because what you see is only a very compact part of the thing, in order to prevent you from having to read 500 LOC...)

Dormilich
03-31-2010, 03:01 PM
This does not really work because as p1 I get a object NodeList from my JS caller script and I dunno why I get this nor can I do anything with it in my case.
upon "encoding" the NodeList (that’s the DOM-Interface (correlates to the JS-constructor) of the p1 object) you receive this object’s string representation, which in JavaScript is [object NodeList]. you would have to serialize (e.g. by JSON, WDDX) this object before sending it to PHP.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum