0

Well i have studied the angular js document and this code works perfect on the same server; somehow not working on cross site; localhost is reachable

module='user';
siteurl='http://localhost/angularjs';
url=siteurl+"/admin/"+module+"/list";
BlockUi();
$http({
        url     :   url,
        method  :   "post",
        data    :   "",
        headers : {'Content-Type':undefined}

    }).then(function(responseText){
        $scope.totaltablerows=responseText.data.response_data;
        $scope.tablerows=$scope.totaltablerows;
        UnblockUi();
        $scope.searchFunction();

    },function(error){
        alert(JSON.stringify(error));
        UnblockUi();
        UnknownError();
    });

What should i do so that this could work.

2
  • Maybe you are missing the port after localhost ? Commented Dec 2, 2015 at 7:30
  • i tried it to? thanks for your response Commented Dec 2, 2015 at 7:34

1 Answer 1

1

If your localhost is where your backend is also running, there is no need to explicitly mention that, so you code would look like:

BlockUi();
$http({
        url     :  "/admin/user/list",
        method  :   "post",
        data    :   "",
        headers : {'Content-Type': 'application/json'}

    }).then(function(responseText){
        $scope.totaltablerows=responseText.data.response_data;
        $scope.tablerows=$scope.totaltablerows;
        UnblockUi();
        $scope.searchFunction();

    },function(error){
        alert(JSON.stringify(error));
        UnblockUi();
        UnknownError();
    });

You do not need to mention the 'http://localhost/angularjs' at the beginning of the URL, also, why are you setting the content-type to undefined

Sign up to request clarification or add additional context in comments.

1 Comment

yup, but you can call it from out of the server; what about that, and content-type:undefined means you can pass the data that may or may not be in json format

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.