0

I've got the weirdest problem. Firstly I'm looking to create a user for my website. I made a RESTful api for the application. Now the problem I am having is:

  1. When ever I click the button to run the $.getJSON js function, it returns TRUE BUT when I check the db, the db hasn't changed.
  2. Now the same link that would appear to do nothing to the db when I console.log() the link and open it in another window it works and inserts into the db. THE LINK IS EXACTLY THE SAME.

My problem is I have no idea why the link sends back true in the $.getJSON function but doesn't update the db but in a new browser window it updates the db because I'm querying the exact same link, with the exact same backend code and the same db.

Here is the $.getJSON function

var LinkSend = AddressAccess + "Home/usercreate/name/"+response.first_name+"/surname/"+response.last_name+"/email/"+response.email+"/contact/"+numberfacebook+"/password/"+null+"/university/"+universityfacebook+"/FB/"+response.id+"/format/json";

$.getJSON(LinkSend,
function(data)
{
   console.log(data.result);
   console.log(LinkSend);
}

$.getJSON does everything correctly just that it never updates the db, how is this even possible? I know the question is a bit flimsy but as people help I'm more than happy to post code as need to identify the problem. I'm also not sure if its a server problem or an internet connection problem?

The internet connection I'm using isn't stable so I don't know if packets are being dropped and for some reason the server replies with a 'true' even though it wasn't inserted into the db.

I'm also using a hostgator server, so I don't know if for some weird reason as the php tries to insert into the db, for some reason its not able to?

Like I said I'm not 100% why this is happening. Any help would really be appreciated.

user481610
  • 3,230
  • 4
  • 54
  • 101

2 Answers2

0

Oh, sorry I didn't mark jquery native function first.

there is no jquery tag on your question by the way.

so after reading http://api.jquery.com/jquery.getjson/

and some examples

your code shoud be:

$.getJSON(LinkSend,
{},
function(data)
{
   console.log(data.result);
   console.log(LinkSend);
}

because 1 parameter us url

2 parameter is sending parameters to the url

3 parameter is function called on success

http://api.jquery.com/jquery.getjson/#jQuery-getJSON-url-data-success

Alex
  • 16,739
  • 1
  • 28
  • 51
0

I post this here for people who might be experiencing a similar problem. The reason for the peculiar behaviour was that I was using Google's Chrome. Now since the internet connection wasn't very stable Chrome was caching the $.getJSON requests from previous calls. Hence the reason why it returned true but nothing happened on the database, simply because the call never went to the database.

Here is a link to switching off the caching in Chrome

Community
  • 1
  • 1
user481610
  • 3,230
  • 4
  • 54
  • 101