PDA

View Full Version : Ajax problem



crisedward
8 Aug 2011, 8:36 AM
Hi, im trying to use ajax on my app, the problem is that the responseText is always empty, im doing a simple login so there should be no problem.

this snippet is in my index.js


Ext.get('login_button').on('click', function(evt,t,o) {
//do stuff
user = document.getElementById('user').value;
password = document.getElementById('password').value;
Ext.Ajax.request({
url : 'scripts/ajax.php' ,
params : { user : user, password: password },
method: 'GET',
success: function ( result, request ) {
Ext.Msg.alert('Success', result.responseText);
console.log(result);

},
failure: function ( result, request) {
Ext.Msg.alert('Failed', result.responseText);
}
});
});


and this is my ajax file



<?phprequire_once("db.php");
if(isset($_REQUEST['email']) && isset($_REQUEST['password'])){
$email = mysql_real_escape_string($_REQUEST['email']);
$password = md5(mysql_real_escape_string($_REQUEST['password']));
$sql = "SELECT * FROM User WHERE email = '$email' AND password = '$password'";
$result = mysql_query($sql);
$r = mysql_fetch_assoc($result);
if($r){
session_start();
$user_session = array(name => $r['Name'], lastname=> $r['Lastname'],email => $r['Email']);
$_SESSION['user_session'] = $user_session;
echo json_encode($user_session);
}else{
echo "false";
}}

?>

mitchellsimoens
8 Aug 2011, 1:38 PM
What framework are you using so I can move and maybe help you?

crisedward
8 Aug 2011, 2:07 PM
Im using Sencha-Touch version 1.1.0

mitchellsimoens
8 Aug 2011, 2:08 PM
Im using Sencha-Touch version 1.1.0

Ok, I have moved into the correct forum. Now, have you looked at the response coming back in the Chrome or Safari dev tools?

crisedward
8 Aug 2011, 2:13 PM
yes, it returns me an object with responseText: "", but it should be something because on my ajax.php file im printing something, also i tried doing an sql insert and it doesnt work, but if i try using the browser to access the ajax.php file it does print a response and do the query

mitchellsimoens
8 Aug 2011, 2:15 PM
OK... but have you looked in the network tab of the dev tools on the browser to inspect the request and response?

crisedward
8 Aug 2011, 2:21 PM
yes, its sends a request ajax.php with the next headers:

Request URL:
http://localhost/mobile/scripts/ajax.php?_dc=1312842202102&user=test&password=test
Request Method:
GET
Status Code:
http://www.sencha.com/forum/chrome-devtools://devtools/Images/successGreenDot.png200 OK
Request Headersview source

Accept:
*/*
Accept-Charset:
ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:
gzip,deflate,sdch
Accept-Language:
es-ES,es;q=0.8
Connection:
keep-alive
Cookie:
PHPSESSID=83vl387vtaj7o1jafmdmebq034
Host:
localhost
Referer:
http://localhost/mobile/
User-Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.107 Safari/535.1
X-Requested-With:
XMLHttpRequest

Query String Parametersview URL encoded

_dc:
1312842202102
user:
test
password:
test

Response Headersview source

Connection:
Keep-Alive
Content-Length:
0
Content-Type:
text/html
Date:
Mon, 08 Aug 2011 22:18:50 GMT
Keep-Alive:
timeout=15, max=98
Server:
Apache