1 Replies - 1702 Views - Last Post: 11 January 2013 - 01:04 AM

#1 hwoarang69   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

ajax dont open php file

Posted 10 January 2013 - 03:15 PM

i am new to ajax and not sure why this isnt working. when user click on link in index.php than ajax should run. in ajax it will open a cart_del_item.php file where the main code will run. this way the page wont reload every time user hit the link in index.php.

the problem is in jquery.js file. for some reason it wont open cart_del_item.php file.

<a href='cart.php?del_id=$image_id_db' id='linkx' name='linkx'>
            <img src='IMAGE/x.png' id='imgx' />


        type: 'POST',
        url: 'cart_del_item.php',    
        data: 'del_id_d=' + 2

    $del_id_p = $_POST['del_id_d'];

    $delete_query = mysql_query("DELETE FROM item_cart WHERE item_id = '$del_id_p'") or die(mysql_error());

in jquery.js i also trying putting this:
        //alert('ajax request complete - might be error ex value string has numbers?'); 
        //alert('ajax request success - Every thing works');

the complete works but success doesnt work.

Is This A Good Question/Topic? 0
  • +

Replies To: ajax dont open php file

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4271
  • View blog
  • Posts: 13,521
  • Joined: 08-June 10

Re: ajax dont open php file

Posted 11 January 2013 - 01:04 AM

View Posthwoarang69, on 10 January 2013 - 11:15 PM, said:

the complete works but success doesnt work.

the complete code does work, you’re just not staying long enough on the page to get a result.

to be more detailed, when you click on that link, two things happen: JS executes the jQuery event handler that sends the AJAX request. if the request was sent, the browser follows the URL given in the href attribute. but that is still before the AJAX request returns.

there are several solutions (in descending order):
- drop the link and attach the handler on the image
- drop the href attribute
- prevent the browser from following the URL
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1