none
REST call - Error: The expression is not valid RRS feed

  • Question

  • Hi,

    I have a custom list in which I have a dropdown and 2 single line of text field.

    I am trying to query the dropdown and fill the textbox from another list. Below is the code I have tried:

    $('select[title="Skill"]').change(function (event) { 
    	
    var vals = $('select[title="Skill"]').find('option:selected').text();
    				
    var listname = "MySkills";
    		
    var resurl = siteURL + "/_api/web/lists/getbytitle('" + listname + "')/items?$select=Capability,Specialty and Title eq 'vals'"; 
    
    		$.ajax({
    				url: resurl,
    				method: "GET",
    				headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {	 	 
    var items = data.d.results;
    					
    if(items.length > 0){
    // assign data to textbox
    						}
    				},
    error: function (data) {
    alert(data.responseText);		
    				}
    			});
    	
    	});	

    How to correct the expression?

    Thanks

    Monday, April 17, 2017 11:26 AM

Answers

  • Change your URL to below...

    var resurl = siteURL + "/_api/web/lists/getbytitle('" + listname + "')/items?$select=Capability,Specialty&$filter=Title eq 'vals'"; 

    To Get Capability and Specialty value use below code inside if block(if(items.length > 0))

    $.each(data.d.results, function(key, val) {
    
     console.log(val.Capability);
     console.log(val.Specialty);
    
    });



    • Edited by Dillibabub Monday, April 17, 2017 11:54 AM
    • Marked as answer by Venkatzeus Tuesday, April 18, 2017 9:52 AM
    Monday, April 17, 2017 11:50 AM
  • Use Below Code

    var vals = $('select[title="Skill"]').find('option:selected').text();
    https://site/_api/web/lists/getbytitle('MySkills')/items?$select=Title,Capability,Specialty&$filter= Title eq '"+vals+"'";


    Monday, April 17, 2017 1:07 PM
  • Hi,

    Just some tip for your reference:

    You could test the REST URL in browser first, if it works fine. Try to build the URL by JavaScript.

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Venkatzeus Tuesday, April 18, 2017 9:52 AM
    Tuesday, April 18, 2017 5:00 AM

All replies

  • Change your URL to below...

    var resurl = siteURL + "/_api/web/lists/getbytitle('" + listname + "')/items?$select=Capability,Specialty&$filter=Title eq 'vals'"; 

    To Get Capability and Specialty value use below code inside if block(if(items.length > 0))

    $.each(data.d.results, function(key, val) {
    
     console.log(val.Capability);
     console.log(val.Specialty);
    
    });



    • Edited by Dillibabub Monday, April 17, 2017 11:54 AM
    • Marked as answer by Venkatzeus Tuesday, April 18, 2017 9:52 AM
    Monday, April 17, 2017 11:50 AM
  • Hi ,

    I changed that, but the "vals" text is not going

    I added the console.log for the resulr, and I get this:

    https://site/_api/web/lists/getbytitle('MySkills')/items?$select=Title,Capability,Specialty&$filter= Title eq 'vals'

    vals has the correct text, which is got by:

    var vals = $('select[title="Skill"]').find('option:selected').text();

    How to pass the "vals" text in the URL?

    Thanks

    Monday, April 17, 2017 12:50 PM
  • Use Below Code

    var vals = $('select[title="Skill"]').find('option:selected').text();
    https://site/_api/web/lists/getbytitle('MySkills')/items?$select=Title,Capability,Specialty&$filter= Title eq '"+vals+"'";


    Monday, April 17, 2017 1:07 PM
  • Hi,

    Just some tip for your reference:

    You could test the REST URL in browser first, if it works fine. Try to build the URL by JavaScript.

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Venkatzeus Tuesday, April 18, 2017 9:52 AM
    Tuesday, April 18, 2017 5:00 AM