0

I am getting the error "Uncaught SyntaxError: Unexpected identifier" with this AJAX call, I've tried a few workarounds but none seem to work... any ideas? Thanks in advance.

$.ajax({
            type: 'POST',
            url: 'ajaxManager2.php',
            data:{'name1=' $targetName, 'name2=' $sourceName},
            success: function() {
                alert("swap success");
            } 
        }); 

$targetName and $souceName are global variables so no problem there... I think I'm have trouble with the syntax...

0

2 Answers 2

3

The post/get method dont accept the data object as you try to post it.

You should change data:{'name1=' $targetName, 'name2=' $sourceName},

to

data:{name1: $targetName, name2: $sourceName},

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I did this and yep it managed to fix the error, but I am now getting another error (jquery error) which I think must be beacuase of how I recieve the data on my php page; im running a filter input and sanitizing the string, but Im not sure if this is the correct way to recieve in this type of ajax...
you will have to update your question or make a new one
3

The issue is with the syntax of your object you provide to data. Keys should not contain = and the pairs should be separated by :. Try this:

data: { 
  name1: $targetName, 
  name2: $sourceName 
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.