Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

spservices different results in IE and Chrome.

Why is the following working in IE only?  It does not work in Chrome or firefox.  In firefox, I believe it has something to do with spservices.

/ JavaScript source code
$(document).ready(function () {
    SP.SOD.executeOrDelayUntilScriptLoaded(retrieveData, "sp.js");
    //'SP.ClientContext',
    itemProjectNumber = getQueryString('projNumber');

    //Check to see if project number exist. If so, change buttons to update from submit
    var itemIDPPD = getID(itemProjectNumber, "Procurement Plan (Design)");
    if (itemIDPPD) {
        alert(itemIDPPD);
        $("#design_procPlan").hide();
        $("#updDesign_procPlan").show();
    }
    else {
        $("#design_procPlan").show();
        $("#updDesign_procPlan").hide();
    }

    $("#updDesign_procPlan").on("click", function () {
        updateItem(itemIDPPD, "Procurement Plan (Design)");
    });

});

var getQueryString = function (field, url) {
    var href = url ? url : window.location.href;
    var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
    var string = reg.exec(href);
    return string ? string[1] : null;
};

function getID(pid, category) {
    var qry = "<Query><Where>" +
				     "<And>" +
         				"<Eq>" +
            				"<FieldRef Name='PlanningCategory' />" +
            				"<Value Type='Choice'>" + category + "</Value>" +
         				"</Eq>" +
         				"<Eq>" +
            				"<FieldRef Name='ProjectNumber' />" +
            				"<Value Type='Text'>" + pid + "</Value>" +
         				"</Eq>" +
      				"</And>" +
   				  "</Where>" +
   			  "</Query>";

    $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Project Projections",
        CAMLViewFields: "<ViewFields>" +
      					"<FieldRef Name='ID' />" +
      					"<FieldRef Name='PlanningCategory' />" +
      					"<FieldRef Name='ProjectNumber' />" +
   					 "</ViewFields>",
        CAMLQuery: qry,
        completefunc: function (xData, Status) {    //<-- In firefox, when I'm stepping through each line, it skips this to line 64
            //alert(xData.responseXML.xml);
            itemID = $(xData.responseXML.xml).find("z\\:row").attr("ows_ID");
            //	        alert(itemID);
        }
    });

    return itemID;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I see you put async: false
but modern browser disable and don't allow this as it froze the browser and it's not acceptable, human are master of the computer and should stay master of it. using async: false your computer say : "dont touch anything human, I'm working and I will give you hand on me when I will be ready for that"
Avatar of Isaac

ASKER

Strange.  Now it's appearing in Chrome and Firefox correctly but not IE.
Actually, the changes are not reflected in IE when I F12.  Even after I do a hard refresh, delete browser history and restart my computer, the changes are still not reflecting in IE.  very strange behavior
if you don't see the changes on IE, it may be related to your server, try to open the JS file directly in your IE browser
Avatar of Isaac

ASKER

It finally updated but I get a new error
User generated image
it's an other code.
add a dot after "document"
document.getElementsByName
and not :
documentgetElementsByName
but again, this is over the issue described here...
Avatar of Isaac

ASKER

Actually, the file in the server never updated.  It reverted back to the old code and not with the changes you suggested.  It did the same in Chrome and Firefox.  I am contacting the SharePoint host right now.
Avatar of Isaac

ASKER

Ok.  It was my fault.  I had two of the same functions in my code.
Below is an excerpt of the code and attached is my code.
    getID(itemProjectNumber, "Procurement Plan (Design)", part2);
});


var part2 = function (itemIDPPD) {
    console.log(itemIDPPD);   //<--- UNDEFINED so it causes an error in other places.
    if (itemIDPPD) {
        //alert(itemIDPPD);
        $("#design_procPlan").hide();
       

Open in new window

Please see attached file.
Avatar of Isaac

ASKER

'itemIDPPD' shows up as undefined
we're over this question.
Currently, your query return nothing so itemIDPPD is null
<rs:data ItemCount="0"></rs:data>

result of th query look like : xData.responseXML.xml
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
					<rs:data ItemCount="0">
					</rs:data>
				</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>

Open in new window

Avatar of Isaac

ASKER

Thanks leakIm971!

I had to strip the code and break it down to bare minimum in jsFiddle for me to get it.  I think the problem in my call to the SharePoint list as you mentioned.

https://jsfiddle.net/isogunro/g2cr896a/