I have a jquery ajax that is supposed to be sending the selected option from a dropdown using onchange to call the function with the ajax in it. the ajax calls back to a php page that returns HTML for another dropdown, using the input provided by the ajax, that is then appended to the section containing the previous dropdown.
The problem is that instead of sending the get data to the php I get an error, in chrome dev tools, that says GET 404 and the page it is showing is the URL I was at with undefined appended to it. This really confuses me cause i do basically the same thing at another section in the page but with a <p></p> as the onclick but the AJAX is almost identical and even goes to the same php page. This makes me think that it is something to do with the dropdown. Why is it trying to send it to a page called undefined it should be sent to the php page specified in the ajax.
Here is my jquery:
- function fetchCMS(fieldType){
- $.ajax({
- type: "GET",
- url: "functions.php",
- data: "action=getCMS&pageType="+fieldType,
- dataType: "json",
- success: function(type) {
- $(type).appendTo('#eExp');
- }
- });
- };
and here is the markup.
- <p class="admin" id="eExp" title="Click to Expand">Content Management
- <span id="editExpand">[+]</span>
- </p>
- <select id="pageSelect" name="type" onchange="fetchCMS(this.value)">
- <option selected value="">Select Page</option>
- <option name="pageType" value="2">main</option></select><br />
let me know if you need the php too but i didnt think it was relevant as its not even getting that far.
any help is appreciated.