0

UPDATE

Added this error, just says "Error caught"

<script type="text/javascript">
window.onerror = function() {
    alert("Error caught");
};

xxx();
</script>

This is not working, I don't understand why.

My php script inserts data properly if called by itself without an if{method=post} statement

I tried with and without an if method = post argument on the php side to get the ajax below to work but I can't tell if the script is being called at all.

My aim is to submit the data without the user knowing, it's a coordinate / dimension update for a variable design interface.

This is my ajax insert which is supposed to work when a function is invoked after the stop is triggered eg. after an object is done moving which the function is invoked properly as I have set up sequential alerts to pop up after certain lines.

$("#form").submit(function(event){
    event.preventDefault();
    var $form = $( this ),
    url = $form.attr( 'action' );
    var posting = $.post( url, {
        id: $('#id').val(),
        name: $('#name').val(),
        wname: $('#wname').val(),
        xcor: $('#xcor').val(xcor),
        ycor: $('#ycor').val(ycor),
        xwid: $('#xwid').val(xwid),
        yhei: $('#yhei').val(yhei),
        photo: $('#photo').val(),
        targeturl: $('#targeturl').val()
    });

    posting.done(function( data ){
        alert('success');
    });
});
pearlescentcrescent
  • 143
  • 1
  • 3
  • 10
  • 1
    Try adding a `fail` handler and see what it tells you – adeneo Feb 26 '15 at 21:01
  • 1
    Look at the request in your console – epascarello Feb 26 '15 at 21:04
  • I tried to add the error script above, it just says error, wonder how it can say more? Also if the console is f12, I tried that it doesn't say anything? I have seen some code with the word console.log in it, maybe that is what I'm supposed to do? – pearlescentcrescent Feb 26 '15 at 21:06
  • Ahh... use of getPreventDefault() is deprecated, what is the update then? I don't know what xxx() is... – pearlescentcrescent Feb 26 '15 at 21:07
  • jeez, I've been using jquery version 1.7.2 and I upgraded, haven't faced so many problems, adding migrate for deprecated functions also caused more errors... man my friend was right about code FUBAR or code entropy anyway – pearlescentcrescent Feb 26 '15 at 21:20

1 Answers1

3

This is wrong

    xcor: $('#xcor').val(xcor),
    ycor: $('#ycor').val(ycor),
    xwid: $('#xwid').val(xwid),
    yhei: $('#yhei').val(yhei),

Those object are holding jQuery objects, not a value.

Looks like you want to set the value and use the new value. This makes me cringe, but it would do the job

    xcor: $('#xcor').val(xcor).val(),
    ycor: $('#ycor').val(ycor).val(),
    xwid: $('#xwid').val(xwid).val(),
    yhei: $('#yhei').val(yhei).val(),

You would be better off updating them before the call and just using the variable when setting the object. Or just use jQuery serialize() and don't deal with grabbing the elements.

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • I am getting those values, when I used serialize data the values are updated using that... how should I do it then? Actually I modified that, initially the values were updated before the submit function was called, eg. they were just .val(); – pearlescentcrescent Feb 26 '15 at 21:08
  • 1
    It has the form element in it, not a value. – epascarello Feb 26 '15 at 21:08
  • 1
    When they were just val it was CORRECT – epascarello Feb 26 '15 at 21:44
  • The problem now is that the variables seem to be empty, the values sent are not empty but according to the php script, the variables aren't declared, eg. an index problem error for every single variable. I turned that error of using an isset like this but the values aren't recorded if(isset($_POST['yhei'])){ $yhei = $_POST['yhei']; } – pearlescentcrescent Feb 26 '15 at 22:29
  • This was super helpful http://stackoverflow.com/questions/17887098/two-post-requests-one-after-the-other-second-post-request-doesnt-get-execut/17887642#17887642 – pearlescentcrescent Feb 26 '15 at 22:46