Cross-Domain Ajax call with JSNOP in PhoneGap


Client side script:


	var url = base_url;  // you'll want to change

	$.ajax({
		type: 'GET',
		url: url,
		contentType: "application/json",
		dataType: 'jsonp',
		crossDomain: true,
		data: {
			username: $('#username').val(),
			password: $('#password').val()
		},		
		beforeSend: function ( xhr ) {
			//show your image loader here
			$('.loader-image').fadeIn(100);
		},
		success: function ( res ) {
		    //hide your image loader
			$('.loader-image').fadeOut(100);
			if( res.value === 2 ) {
				//unsuccessful code goes here
				return false;
			}
			if( res.value === 1 ){
				//success code goes here
			}
		}
	});

Server side code:


$email = $_GET['username'];
$pass = $_GET['password'];

$user = DO user query using $email and $pass checking.

if (!empty($user)) {
	$value = 1;
} else {
	$value = 2;
}
$theName->value = $value;
echo $_GET['callback'] . '(' . json_encode($theName) . ')';	

Advertisements

2 responses to “Cross-Domain Ajax call with JSNOP in PhoneGap

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s