jqxhr to local server can't find php file

352 Views Asked by At

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.

1

There are 1 best solutions below

6
On

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 ); });