No data is added to DB


#1

I am trying to create a record and it works on the swagger dashboard, but not from my local machine nor jsfiddle. The ajax call returns successfully, but no data is added to the database. There are no javascript errors. Here is my javascript:

var ip = "1.2.3.4";
var url = "https://dsp-sitename.cloud.dreamfactory.com:443/rest/URMobileStats/AdViews?app_name=URMobileStats";
/*var record = {
    "AdID": "1",
    "DateTime": String(new Date($.now())),
    "ClickedBool": "0",
    "OS": navigator.platform,
    "IP": ip,
    "Position": ""
};*/

var record = {"AdID":5,"DateTime":"Fri Aug 22 2014 18:04:47 GMT-0600 (Mountain Daylight Time)","ClickedBool":"0","OS":"Win32","IP":"1.2.3.4.5","Position":""};

$.ajax(
    {
        type: "POST",
        url: url,
        data: record,
        dataType: "jsonp",
        success: function () { alert('success'); },
        error: function (XHR, textStatus, errorThrown) {
            alert("error: " + errorThrown);
        }
    });

#2

What happens when you get rid of JSONP as the datatype and just use JSON?
You also don’t need the port number in your url for hosted DSPs.
If you are working from the desktop, or a jsfiddle, you’ll have to enable CORS if you haven’t done so already.


#3

Ok. I’m trying to test the JSON, which I have done before but I can’t remember which error it returned. Right now I am getting a 403 error so I can’t access read/write. Let me see if I can figure this out first. Otherwise, is it possible to do writes to a database using JSON cross domain? My mobile app needs to write to the database for all users, but I’ve read you cannot do POSTS with JSONP. I have enabled CORS for all (using *).


#4

Alright I had to reconfigure my Roles and permissions. When I change jsonp to application/json I got an error 400: bad request. I also got rid of the port number. I figured out that I needed to put “record”:{} around the data. I changed application/json to json and it appears to be working. Thanks.