dimanche 12 avril 2015

javascript post failing others work fine - form related

I'm trying to POST some data extracted from a form via onsubmit. The POST fails (firebug shows it as a failure) even though the headers and POST data look fine. I've got plenty a number of other POST's working fine. The code used is a copy of exiting code just with a few changes (the response function and the php function called).


I've tried reducing the data to be sent to a minimum, it still fails. I've also tried reducing the called PHP function to just echo a small string, literally just the one line.


The only difference that I can see is that this process is invoked from the forms onsubmit. Here's some of the code:


First the form (part of it)



<form id="jmcase" onsubmit=" return FLWG_editSubmit(18)" method="post">
<input id="jmcasename" type="text" size="150" value="Butler v Time [2015] 234" name="jmcasename">
<input type="submit" value="Submit">........
</form>


The FLWG_editSubmit function called:-



function FLWG_editSubmit($caseid) {

// Build variables to be posted
var pstv = 'FLWGcaseid='+caseid;
// get lists from form
pstv = pstv+formToPostVars('jmjudge','r,,sdl,tdl,udl');
pstv = pstv+formToPostVars('jmcat','r,,sdl,tdl,udl');
pstv = pstv+formToPostVars('jmcsl','r,,sdl,tdl');
pstv = pstv+formToPostVars('jmsid','r,,sdl,tdl');
pstv = pstv+formToPostVars('jmauth','r,,sdl,tdl');
pstv = pstv+formToPostVars('jmact','r,,sdl,tdl');
**updateCase**(caseid,pstv);

//var obj = newRequestObject();
//obj.onreadystatechange = function() {
// if (obj.readyState == 4) {
// if (obj.status == 200) {
// editCaseReturn(htmlspecialchars_decode(obj.responseText, 'ENT_QUOTES'));
// delete obj;
// obj = null;
// }
// }
//}
//obj.open('POST','include/FLWG_updateCase.php',true);
//obj.setRequestHeader('Accept-Charset','utf-8');
//obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//obj.send("TEST=XXX");`enter code here`

}


Function updateCase is another version of the commented out code, which is itself a copy from working POST's (although the commeneted verson was last used to send just a snippet of data which also failed). Here it is anyway:



function updateCase(caseid,pstv) {

var obj = newRequestObject();
obj.onreadystatechange = function() {
if (obj.readyState == 4) {
if (obj.status == 200) {
browseCaseReturn(htmlspecialchars_decode(obj.responseText, 'ENT_QUOTES'));
delete obj;
obj = null;
}
}
}
obj.open('POST','include/FLWG_ucase.php',true);
obj.setRequestHeader('Accept-Charset','utf-8');
obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
obj.send(pstv);
}


I've just tried removing the method="post" from the form. This resulted in a POST error 414 URI too large (data can be large as they are court cases) so I assume it defaulted to get. I changed it back to method="post" and no 414.


My guess is that perhaps the form is POSTing and for some reason my POST fails because the form's POST hasn't been processed. If so then how can I stop the form posting (saw posts that say better to use onsubmit rather than onclick). I've searched through quite a few posts on here but none appear to cover this issue. I'm quite sure that there's no issue with the underlying data being sent (the request POST shows all the expected data in the respective POST variables).


Any assistance/advice would be greatly appreciated.


PS This is my first post.


Aucun commentaire:

Enregistrer un commentaire