0

I got this error for my code. I am getting the alert success, but after that it stops..

    <script>


function PreSaveAction()
{
  var userName = $("input[title='Feature Name Required Field']").val();
  var phoneVal = $("select[title='Platform'] option:selected").text();

  var itemId = GetUrlKeyValue("ID", false, location.href);
//alert(itemId);    
 // var itemId = getParameterByName("ID");
  if (itemId == "")
     itemId = 0;



var lstItemCount = 0;
  if (userName !== null && userName !== "" && phoneVal
     !== null && phoneVal !== "")
  {
     var siteUrl = _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/getByTitle('Features')/items?$filter=((Feature_x0020_Name eq '" + userName + "') and (Platform eq '" + phoneVal + "') and (Id ne " + itemId + "))";
     jQuery.ajax({
        url: siteUrl,
        async: false,
        method: "get",
        headers: { "Accept": "application/json; odata=ver+bose" },
        success: function (data) {
        alert("Success");
           lstItemCount = data.d.results.length;
     },
     error: function (data) {
        $("#errorMsg").text("ERROR: Request failed");
        $("#errorMsg").css({ display: "block" });
        return false;
     }
  });
}
if(lstItemCount > 0)
  {
     $("#errorMsg").text("ERROR: Item Already Exists");
     $("#errorMsg").css({ display: "block" });
     return false;
  }
  else
  {
     return true;
  }

}

</script>
  • 1
    try making sure your accept header reads "application/json;odata=verbose" there is an error there as it stands -- if that doesn't fix the issue try logging the data object directly into the console or an alert box to inspect it – John-M Nov 23 '15 at 14:55
  • replace "odata=ver+bose" with "odata=verbose"... also verify you have mentioned ID "not equal to", is that what u want? – Gaurravs Nov 23 '15 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.