Prototype AJAX Issues

M

morganwhitney

Hi all, I am developing a web app and I am implementing the JavaScript
using the Prototype Framework. I have done all the same stuff from
scratch in a previous application and it worked fine, but I am having a
couple of issues when trying to use Prototype.

1. Parameters are not sent if I specify a transport method:

var url = baseurl+'lib/login.php';
var pars = 'login=' + $F('ad_login') + '&passwd=' + $F('passwd');
var myAjax = new Ajax.Request(
url, {
method: 'get',
parameters: pars,
onComplete: showResponse
}

If I specify either get or post for the method, the parameters do not
get since. I removed the line "method: 'get'," completely and then it
started sending the parameters via post. This is OK since I got it to
work, but it annoys me to no end.

2. ResponseText from AJAX call has extra white space.

my showResponse function that gets called by the onComplete returns the
text with a bunch of extra white space in it. It didn't do this in my
last application and it uses the same PHP script, so I know it is not
actually generating the white space in the response. Because of this,
my application cannot tell whether or not an attempt was successful
because the comparison does not work.

Any ideas?
 
M

morganwhitney

I managed to get the method: part working, but the whitespace issue
persists. I wrote a newline character stripper function and am wrapping
the responses in it before they are evaluated, which works, but it is
ugly:

function ajaxLogin() {
var url = baseurl+'lib/login.php';
//var url = "url/to/the/file//login.php";
var myAjax = new Ajax.Request(
url, {
method: 'post',
parameters: Form.serialize($("loginform")),
onComplete: showResponse
}
);
}

function showResponse(originalRequest) {
var response = originalRequest.responseText;
response = stripNewlines(response);

if (response == "success") {
window.location = "home.php";
} else {
$('loginmessage').innerHTML = response;
}
}
 
M

morganwhitney

Forgot to mention the Firebug thing. I use it, live it, love it.
Firebug is how I noticed the additional whitespace in the first place,
since when viewing it via the webpage you can't tell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top