0

I have updated this question as per Cimbali's suggestion. This is now the js code that specifies the request:

......  
function editFiltName($thisFiltCell)    {
  var cellText=$thisFiltCell.text();
  var idx=$thisFiltCell.index(); //alert("idx: idx");
  var newFN=prompt("Enter new filter name below - up to 12 characters.", cellText); 
    switch (newFN)  {
        case    null        : return;   // cancel key hit
        case    cellText    : return;  // no change
        case    ""          : ; //$thisFCell.text('Filter' + (idx+1));
        default             : $thisFiltCell.text(newFN);    
    }   
    var action='updateFiltName';
    var request = MrAjax(action,newFN,idx);
} // end main function
//*******************************************
function MrAjax(action,P1,P2)  { 
    console.log("Ajax-> action: "+action+" P1: "+P1+" P2: "+P2);
    var jqxhr=$.ajax({  
        type: "POST",
        url: "../phpMain/editTblField.php",
        data: {action:action, P1:P1, P2:P2}
    });
    jqxhr.always(function() { console.log("jqxhr.status: " + jqxhr.status ); });
} // end MrAjax

This is now the console output when I enter some data:

enter image description here

Any suggestions? Note that console error is followed immediately by a 'success' response for the same file. But the php file still does not run. I get no php error response from the server - nor do I see my embedded echo I placed on the 1st line of the php file echo("Got here!);. That's true even when I comment out everything but that line.

I don't think it's in the php code but just in case, here it is:

<?php
echo "Got here!";
?>  

Thanks again for taking a look.

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
Banjobum
  • 57
  • 8
  • Are you sure "finished loading" means a success ? Not just that loading stops since a 404 reply was received ? – Cimbali Dec 11 '14 at 20:05
  • I think you are correct. Good find. When I purposely put a bogus file path into the req I get the same console output. OTOH "finish loading" POST data to a file means to me that it found the file and "finished" loading the data to it. Why else would they include the file/path in the message? I've been studying ajax for a couple of years now and using it successfully pretty much. But it seems I still have a way to go to master it. I guess I can stop looking for that hidden 2nd request :) – Banjobum Dec 11 '14 at 21:12
  • And if you copy/paste the exact URL of that message in your browser, you can load the page ? – Cimbali Dec 11 '14 at 21:23
  • @Cimbali I'm away from my dev system and somehow my current files did not make it into my dropbox so I can't test this. I should be back by tomorrow. – Banjobum Dec 14 '14 at 17:28

1 Answers1

0

Your error comes from a typo in your console log, you mixed up concatenations from different languages.

Instead of console.log("jqxhr.status: " . jqxhr.status ); you want console.log("jqxhr.status: " + jqxhr.status );

A second error seems to be that the status field doesn't exist (from your comment). However, from the jquery doc, http://api.jquery.com/jQuery.ajax/#jqXHR :

The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible.

[...]

For backward compatibility with XMLHttpRequest, a jqXHR object will expose the following properties and methods:

readyState
status
statusText
responseXML and/or responseText when the underlying request responded with xml and/or text, respectively
setRequestHeader(name, value) which departs from the standard by replacing the old value with the new one rather than concatenating the new value to the old one
getAllResponseHeaders()
getResponseHeader()
statusCode()
abort()

I also ready it is a Deferred object, so maybe this strange behaviour comes from trying to access the status field before it exists. Try waiting for the completion of the request.

So instead of console.log("jqxhr.status: " + jqxhr.status );, use the following :

jqxhr.always(function() { console.log("jqxhr.status: " + jqxhr.status ); });

or

jqxhr.always(function(data, textStatus, errorThrown) { console.log("jqxhr.status=" + jqxhr.status + " : " + textStatus ); });
Cimbali
  • 11,012
  • 1
  • 39
  • 68
  • You caught that console.log error. Thanks. After correcting, the console log has now output the message: 'jqxhr.status: undefined'. I've checked the php file location many times and can find no problem. I have working code in other projects that use the exact same file specification: url: "../phpMain/editTblField.php",The file shows up in Win explorer and my filezilla as shown. Also, the last line of console output seems to indicate that the file was successfully loaded. – Banjobum Dec 11 '14 at 18:26
  • What version of jquery are you using ? – Cimbali Dec 11 '14 at 18:40
  • So, I guess I have 2 puzzles here. 1) Why does the jqxhr make another request after logging the 1st as a failure to locate the file? And 2) if the 2nd request worked why doesn't the php file run? I just tried it again after commenting out everything in the php file except the echo "Got here!" line. Still no joy. – Banjobum Dec 11 '14 at 18:41
  • What you suggest seems to make sense. I tried both examples. After 1) the console's log output is: "jqxhr status: 404". After 2) it outputs "jqxhr status:404 : error". The other console lines are the same as shown in the question. Good suggestions though. I'm trying to see if somehow I have 2 slightly different requests embedded in my code somehow. – Banjobum Dec 11 '14 at 19:16
  • At least you don't get 'undefined' anymore, which is a good start. You probably should update your question so we can get to the real problem, and see past the typos etc. – Cimbali Dec 11 '14 at 19:20
  • I just took out the request.done js code which is not relevant - to simplify things further. – Banjobum Dec 11 '14 at 19:54