Привет, ребята Я новичок в angularjs, я просто конвертирую свое приложение из jquery в угловой js. Но я сталкиваюсь с трудностями с запросом ajax в угловых js. Мой код отлично работает в jquery.
Angularjs Код:
links.serverurl = My Another Server Address which is defined another location
$scope.submit = function() {
console.log(this.formData);
$http.get(links.serverUrl).success(function (response) {
console.log(response);
});
JQuery Рабочий код:
var url = "http://pbc.mydev786.com/";
$.get(url+"?"+data,function(response){
$("div[data-role='page']").hide();
$("#showbill").show();
$(".billresult").html(response);
});
Мои Php Headers:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PATCH, DELETE');
header('Access-Control-Allow-Headers: Origin, Content-Type,X-Requested-With');
AngularJs Config:
$myapp.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
$routeProvider
.when('/', {templateUrl: "home.html"})
.when('/electricity', {templateUrl: "electricity.html"})
.when('/evo', {templateUrl: "evo.html"})
.when('/ptcl', {templateUrl: "ptcl.html"})
.when('/suigas', {templateUrl: "suigas.html"})
.when('/iesco', {templateUrl: "iesco.html"})
.when('/lesco', {templateUrl: "lesco.html"})
.when('/fesco', {templateUrl: "fesco.html"})
.when('/kesc', {templateUrl: "kesc.html"})
.when('/extra', {templateUrl: "extra.html"})
.when('/myaccount', {templateUrl: "myaccount.html"});
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
Запрошенные Заголовки:
Accept application/json, text/plain, */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length 20
Content-Type text/plain; charset=UTF-8
Host pbc.mydev786.com
Origin http://localhost:8383
Referer http://localhost:8383/PakistanCheckBill/
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Заголовки ответов:
Connection keep-alive
Content-Encoding gzip
Content-Type text/html
Date Tue, 20 Jan 2015 11:47:43 GMT
Server nginx/1.6.2
Transfer-Encoding chunked
http://stackoverflow.com/a/27950593/967859 –
не сработал, я задал вопрос, отредактированный с большим количеством кода –
. Какую ошибку вы получите, если таковая имеется? Каков ответ от файла сервера? – rwacarter