Showing posts with label post data. Show all posts
Showing posts with label post data. Show all posts

Thursday, November 22, 2018

Call a function of Controller "One" inside Controller "Two" - IONIC1

app.controller('One', ['$scope', '$rootScope'
    function($scope) {
        $rootScope.$on("CallParentMethod", function(){
           $scope.parentmethod();
        });

        $scope.parentmethod = function() {
            // task
        }
    }
]);
app.controller('two', ['$scope', '$rootScope'
    function($scope) {
        $scope.childmethod = function() {
            $rootScope.$emit("CallParentMethod", {});
        }
    }
]);

While $rootScope.$emit is called, you can send any data as second parameter.

Solution for IONIC2+  will be up soon.

Friday, April 19, 2013

Get File Last Modified Date-Time

<?php

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}

?>

this file modify date is used for the mobile application to get updates are available or not on the server file.

Get County from User Lat Long

In Mobile application how the server knows about the posted device country and response then as per the location.

Get the current location of the device and use google map api to get user location. Get location from the ipaddress is a worth thing now. because all the internet user use proxy network.

PHP:

<?php

$cur_lat =$_REQUEST['lat'];
$cur_lon = $_REQUEST['lon'];

Monday, April 1, 2013

Image store in Database.

Get the image URL that you want to store in the database.

$file= "http://sitename.com/image1.jpg";

$imgdata = base64_encode(file_get_content($file));

Above syntax give you a image in encoded formate. Store image data as a text in the database.

Use of image data in html app.
Get data from the database and append "data:image/jpeg:base64," before the data string like below:

data:image/jpeg:base64,imgdata

Use appended string as a source of the image like below:

<img src="data:image/jpeg:base64,skadadjsiweryerjtkHRUWNHDDhASDJKKSDHD=" />

It will display image to the application.. in mobile applications does not need to load image from the server. and its also use for the offline application.

Friday, January 25, 2013

Access-Control-Allow-Origin. issue on Phonegap JqueryMobile

When i ajax call to get or post some Data from Server, Some times I found error like below.

XMLHttpRequest cannot load file://localhost/Users/bhumika/Documents/phonegap-2.2.0/lib/ios/bin/****/www/js/data.json. Origin null is not allowed by Access-Control-Allow-Origin.

to Solve above error write below syntax in your device ready function.

$.support.cors = true;
$.mobile.allowCrossDomainPages = true;

Or  

Write Below syntax in PHP file to the server.
 
header('Access-Control-Allow-Origin: *');
Cheers....

Wednesday, December 26, 2012

Regular expresion to validate URL

var url = value.v_url;

var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

if (pattern.test(url)) {
        content+='<a href="'+value.v_url+'" target="_blank">'; //  Url is valid
}
else{
        console.log("invalid url");
}

Friday, April 27, 2012

Display JSON data

Create a function to get data json data.

function getjson(){
var url = "https://sitename/getdata.php";
requestCrossDomain(url, function(results)
{


// result = {" resultdata ":[{" imgname ":"2147512358.jpg"," name ":"bhumika"},{"imgname
//                  ":"2411827535.jpg"," name ":"rahul"}]}

var myJSONObject1 = eval('(' + results + ')');
if(myJSONObject1== null)
{
return false;
}
$('#content_home').html(CreatedataView(myJSONObject1.resultdata)).fadeIn();
});
return false;
}

Monday, March 19, 2012

Pass all the Form elements to call JSON


If you call any server file on the live server to get json data, then may be you need to transfer some variables with value. for ex. if you need to insert data to your server then you must haveto post all data to server file.

First you need to follow my previous blog(get-data-using-cross-domain-request).

Create one form element and create all the variable into the form tag that you want to post on the server.
Create below function in the .js file.

function createQuery(fname)
{
     var formname= fname;
     var elements = document.getElementById(formname).elements;
     var pairs = new Array();
var next_el = "";
var checkdetail=""
    for (var i = 0; i < elements.length; i++)
   {