2

I'm working on an angular js application. I have loaded jquery and I'm using some jquery methods in this application. My problem is $.ajax. It's working in Firefox and IE, but has problem in google chrome! Google chrome always shows Failed to load response data error in my ajax request. Even if I send ajax request manually with XMLHttpRequest()(without jquery), I still see this error message in the chrome console. I don't know what's the problem and how can I solve this. Everything is perfect in firefox, even IE, but chrome has problem! Here is my ajax code:

$.ajax({
    url: "/testUrl",
    type: "post",
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    headers: {
        Accept: "application/json; charset=utf-8",
        "Content-Type": "application/json; charset=utf-8"
    }
}).success(function(data) {
});

Note, I have used jquery ajax request in a non angular js application before and everything is right in google chrome, but when I switched to angular, I saw this strange problem.

0

2 Answers 2

1

Using jquery with angular is bad practice. Use the angular implementation for Ajax calls $http.

See this post http://www.bennadel.com/blog/2612-using-the-http-service-in-angularjs-to-make-ajax-requests.htm

And the official docs https://docs.angularjs.org/api/ng/service/$http

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

1 Comment

I strongly disagree with your statement, not also to mention that it does not solve the OP's problem. The link that you provide is nowhere near the official documentation, which btw has got a whole page in the tutorial on how jquery can help. You just need to use jQuery in a different way than it is accustomed, and surely it should not be used in the OP's case.
0

In angular you can use build in service $http or $resource

Example:

  var data = ({
    dataType: "json", 
    headers: {
     Accept: "application/json; charset=utf-8",
    "Content-Type": "application/json; charset=utf-8"
}
    });

 $http.post('yoururl', data).success(function(data){
 console.log(data);
 });

Comments

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.