skip to Main Content

I have a js when i do a ajax call to one server. When i call to this service using localhost, works. But when i call to this service using the server where i upload it, its ERROR 500. The call return a json.

 $.ajax({
            url: "https://www.example.com/example",
            dataType: "json",
            data: {
                'data': xml,
                'message': message,
                'customer_id': customer_id,
                'subscr_id': subscr_id
            },
            type: 'POST',
            success: function (devol) {


            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert("no ha entrado");
            }
        });

2

Answers


  1. Try to update your code below:

    var model = {
                'data': xml,
                'message': message,
                'customer_id': customer_id,
                'subscr_id': subscr_id
            };
    $.ajax({
            url: "https://www.example.com/example",
            type: 'POST',
            dataType: 'json',
            data: JSON.stringify(model),
            //headers: { 'authorization': `Bearer ${token}` },
            async: false,
            processData: false,
            contentType: "application/json",
            error: function (err) {
            },
            success: function (data) {  
            }
        });
    
    Login or Signup to reply.
  2. It might be because of CORS (Cross-Origin Resource Sharing)… Usually, you cannot make calls to other domains from the browser unless the other domain you are making calls allows CORS to all sites or specific sites.

    enter link description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search