javascript - AJAX request not working on remote host -


i've got ajax request pulls data form , posts api. weird thing works fine on localhost fails silently when upload remote server. , mean silently: response code blank, there's nothing in logs. i've checked on firefox , chrome. jquery loaded, function firing properly. code below:

function send() {     console.log("preparing");     var beacon = {         beaconid: $("#beaconid").val(),         name:$("#beaconname").val(),         campaignid:$("#campaignid").val(),         clientid:$("#clientid").val()     }     console.log("payload:");     console.log(beacon);      $.ajax({         type: 'post',         url: '../beaconapi/index.php/createbeacon',         data: json.stringify(beacon),         contenttype: "application/json; charset=utf-8",         traditional: true,         success: function (response) {             console.log("done:");             console.log(response);         },         error: function(jqxhr, textstatus, errorthrown) {             console.log(json.stringify(jqxhr));             console.log("ajax error: " + textstatus + ' : ' + errorthrown);          }     }); } 

from comments posted

10:33:21.046 "{"readystate":0,"responsetext":"","status":0, "statustext":"error"}" addbeacon.html:34 10:33:21.046 "ajax error: error : " 

a status code of 0 means 1 of 2 things:

  1. you running off file protocol
  2. the page refreshed ajax call made

since said on production, sounds case of #2.

so need cancel action causing page refresh. since not show how call send, here basic ways of cancelling action.

onclick="send(); return false"  onsubmit="send(); return false"  $("#foo").on("click", function(e) {     send();     e.preventdefault(); }); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -