I create an mobile app with phonegap and I dont know how smart it is but I want to user to reg. on my app with their phone number and PIN. Users will download app, type phone number and get PIN via text message (SMS) (twillio api)... Now I have basic problem how to run an laravel php code with ajax cross domain.
I do:
HTML+JS+ajax:
<body class='bg-blue'>
</br>
<h1 class="text-center">AgroAgro</h1>
</br>
<h4 class="text-center">Register manager account and add workers.</h4>
</br>
<div class="col-xs-12"><p>Your Phone Number</p></div>
<div class="col-xs-12">
<input class="form-control" placeholder="Your Phone Number"/>
</div>
<div class="col-xs-12"></br></div>
<div class="col-xs-12 text-center">
<button id="createPin" class="btn btn-success btn-lg">FREE sign up</button>
</div>
<footer>We will send you a PIN code via text message immediately to login and get started. We will never share or span your phone number.</footer>
<script>
$(function() {
$('#createPin').click(function(e) {
e.preventDefault();
$.ajax({
url: "localhost:8000/createPin",
type: "POST",
async: true,
data: { phoneNumber:$("#createPin").val()},
dataType: "json",
success: function(data) {
console.log(data);
//do something
},
error: function (data) {
console.log(data);
}
});
});
});
</script>
on backend side I write php with laravel framework:
Route::put('createPin', function()
{
$phoneNumber = Input::get('phoneNumber');
$pin = rand(1000,9999);
$user = new User;
$user->phoneNumber = $phoneNumber;
$user->pin = $pin;
// this line loads the library
require('/path/to/twilio-php/Services/Twilio.php');
$account_sid = 'AC6333333911376fghhbced190522da587';
$auth_token = '[AuthToken]';
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array(
'To' => $phoneNumber,
'From' => "+18702802244",
'Body' => "PIN code",
'MediaUrl' => "Your pin code is ".$pin,
));
$user->save();
return $users;
});
When I click on button with IDcreatPin I get this error:
XMLHttpRequest cannot load localhost:8000/createPin. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.
How I can solve this problem? Also what you think about idea of PIN instead password?